diff --git a/block-comment.el b/block-comment.el new file mode 100644 index 0000000..3067ffa --- /dev/null +++ b/block-comment.el @@ -0,0 +1,13 @@ +(defun nix-block-comment () + "Insert a block-comment." + (interactive "*") + (let ((beg (region-beginning)) + (end (copy-marker (region-end)))) + (goto-char beg) + (insert "/*") + (unless (eolp) + (newline) + (goto-char end) + (unless (and (bolp) (looking-at "[ \t\r]*$")) + (newline 1) + (insert "*/"))))) diff --git a/tests/nix-mode-tests.el b/tests/nix-mode-tests.el index 6b4564e..d694860 100644 --- a/tests/nix-mode-tests.el +++ b/tests/nix-mode-tests.el @@ -249,5 +249,32 @@ Related issue: https://github.com/NixOS/nix-mode/issues/94" "Proper indentation of let expressions." (with-nix-mode-test ("issue-128.nix" :indent 'nix-indent-line))) +(defmacro nix-mode-test (contents &optional debug &rest body) + "Create temp buffer in `nix-mode' inserting CONTENTS. +BODY is code to be executed within the temp buffer. Point is + at the end of buffer." + (declare (indent 1) (debug t)) + `(with-temp-buffer + (insert ,contents) + (nix-mode) + (when ,debug + (switch-to-buffer (current-buffer)) + ,@body))) + +(ert-deftest nix-mode-block-comment-test-8dycMu () + "Test block-comments." + (nix-mode-test + "Block comments +can span multiple lines." + nil + (goto-char (point-max)) + (push-mark) + (goto-char (point-min)) + (nix-block-comment) + (goto-char (point-max)) + (should (looking-back "*/" (line-beginning-position))) + (goto-char (point-min)) + (should (looking-at "/*")))) + (provide 'nix-mode-tests) ;;; nix-mode-tests.el ends here