branch: elpa/annotate commit cb8212830da5b723f4ad03809588ad25715c024a Author: cage <cage@invalid> Commit: cage <cage@invalid>
- added feature when the customizable variable `annotate-endline-annotate-whole-line' is not nil (default t), and the user try to annotate a newline the whole line is annotated instead (or the next if the line is empty). If `annotate-endline-annotate-whole-line' is nil annotating a newline will signal an error. --- annotate.el | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/annotate.el b/annotate.el index a94379bee0..af88620e76 100644 --- a/annotate.el +++ b/annotate.el @@ -198,6 +198,13 @@ has been modified outside Emacs." :type 'boolean :group 'annotate) +(defcustom annotate-endline-annotate-whole-line t + "Whether trying to annotate the end of line character will +annotate the whole line before (or after if the line is composed +by the newline character only) instead." + :type 'boolean + :group 'annotate) + (defconst annotate-prop-chain-position 'position) @@ -586,7 +593,13 @@ specified by `from' and `to'." (when (annotate-annotation-at (1- chain-end)) (annotate--cut-left-annotation last-of-chain-to-cut))) (when delete-enclosed - (annotate-delete-chains-in-region chain-end region-stop))))) + (annotate-delete-chains-in-region chain-end region-stop)))) + (annotate-line (eol) + (let* ((bol (annotate-beginning-of-line-pos))) + (goto-char bol) + (set-mark (point)) + (goto-char eol) + (annotate-annotate)))) (let ((annotation (annotate-annotation-at (point)))) (cond ((use-region-p) @@ -631,8 +644,21 @@ specified by `from' and `to'." (if (annotate--position-on-annotated-text-p (point)) (signal 'annotate-annotate-region-overlaps nil) (let ((char-maybe-newline (char-after))) - (when (not (char-equal char-maybe-newline ?\n)) - (create-new-annotation)))))) + (when char-maybe-newline + (cond + ((not (char-equal char-maybe-newline ?\n)) + (create-new-annotation)) + ((null annotate-endline-annotate-whole-line) + (user-error "The end of line can not be annotated")) + (t ;; annotate the whole line before or after + (save-excursion + (let* ((bol (annotate-beginning-of-line-pos)) + (eol (point))) + (if (/= eol bol) + (annotate-line eol) + (progn + (goto-char (1+ eol)) + (annotate-annotate)))))))))))) (set-buffer-modified-p t)))) (cl-defun annotate-goto-next-annotation (&key (startingp t))