emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: add-change-log-entry


From: martin rudalics
Subject: Re: add-change-log-entry
Date: Wed, 18 Jul 2007 23:32:50 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

auto-fill-mode uses comment-line-break-function which might be used to do just
that.  Currently fill-paragraph does not offer any comparable hook, but that
could be changed if necessary.

I can do with an after-change-hook as well, look at the attached patch.  The
code would get a bit more complicated if I had to do this without font-lock.
*** add-log.el  Wed Jul 18 20:19:46 2007
--- add-log.el  Wed Jul 18 20:12:48 2007
***************
*** 681,686 ****
--- 681,717 ----
         (pos (save-excursion (indent-line-to indent) (point))))
      (if (> pos (point)) (goto-char pos))))
  
+ (defun change-log-after-change (start end old-length)
+   "Split parenthesized lists when breaking lines.
+ START and END are beginning and end of the changed text.  OLD-LENGTH is
+ the length of the text removed by the change."
+   (when (and font-lock-mode ; Works in font-lock-mode only.
+            (not undo-in-progress) ; Avoid confusing undo.
+            (zerop old-length) ; The change was an insertion.
+            ;; The first inserted character must be a newline.
+            (equal (char-after start) ?\n)
+            (> start (1+ (point-min)))
+            ;; The last char before the insertion must be a comma.
+            (equal (char-before start) ?,)
+            (progn
+              (unless (get-text-property (1- start) 'fontified)
+                ;; Fontify the line, we have to check the face of the
+                ;; character before the comma.  I don't know why the
+                ;; save-excursion is needed here.
+                (save-excursion
+                  (font-lock-fontify-region (- start 2) start)))
+              (eq (get-text-property (- start 2) 'face)
+                  'change-log-list)))
+     (save-excursion
+       (goto-char start)
+       ;; Delete the comma.
+       (delete-char -1)
+       ;; Close this list.
+       (insert ")")
+       (skip-chars-forward " \t\n")
+       ;; Start next list.
+       (insert-before-markers "("))))
+ 
  
  (defvar smerge-resolve-function)
  
***************
*** 704,709 ****
--- 735,741 ----
            '(lambda ()
               (looking-back "^\\s *\\*\\s *" (line-beginning-position))) 
            nil t)
+   (add-hook 'after-change-functions 'change-log-after-change nil t)
    (set (make-local-variable 'indent-line-function) 'change-log-indent)
    (set (make-local-variable 'tab-always-indent) nil)
    ;; We really do want "^" in paragraph-start below: it is only the

reply via email to

[Prev in Thread] Current Thread [Next in Thread]