Box comments

This commit is contained in:
Wojciech Kozlowski 2018-07-11 22:25:11 +01:00
parent e8981a87b7
commit 0fa85533c8
2 changed files with 59 additions and 1 deletions

View File

@ -440,6 +440,65 @@
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
;; --------------------------------------------------------------------------
;; Box comments.
;; --------------------------------------------------------------------------
(defvar box-comment-char/emacs-lisp-mode ";; ")
(defvar box-comment-char/lisp-interaction-mode ";; ")
(defvar box-comment-char/scheme-mode ";; ")
(defun box-comment-char ()
"Return the comment character for the current mode."
(let ((box-comment-var
(intern (format "box-comment-char/%s" major-mode))))
(if (boundp box-comment-var)
(eval box-comment-var)
comment-start)))
(defun make-box-comment ()
(interactive)
(let ((comm-start (box-comment-char))
beg indent len)
;; ----------------------------------------------------------------------
;; Find beginning of comment.
;; ----------------------------------------------------------------------
(end-of-line)
(unless (search-backward comm-start nil t)
(error "Not in comment!"))
;; ----------------------------------------------------------------------
;; Reformat into a single line.
;; ----------------------------------------------------------------------
(unfill-paragraph)
(end-of-line)
(search-backward comm-start nil t)
;; ----------------------------------------------------------------------
;; Set variables.
;; ----------------------------------------------------------------------
(setq beg (point))
(setq indent (current-column))
(setq len (- (- fill-column (length comm-start)) indent))
;; ----------------------------------------------------------------------
;; Reformat comment text in place.
;; ----------------------------------------------------------------------
(goto-char beg)
(insert comm-start (make-string len ?-))
(newline)
(indent-to-column indent)
(end-of-line)
(fill-paragraph)
(unless (bolp)
(progn
(newline)
(indent-to-column indent)))
(insert comm-start (make-string len ?-))))
(global-set-key (kbd "M-'") 'make-box-comment)
)
(provide 'em-programming)

View File

@ -4,7 +4,6 @@
** .emacs.d
- [ ] Port comment block functions
- [ ] Clean up theme file
- [ ] Comments are too dark (problematic with big block comments)
- [ ] Nicer splash screen