emacs-devel
[Top][All Lists]
Advanced

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

Re: electric-pair-mode as a minor mode?


From: João Távora
Subject: Re: electric-pair-mode as a minor mode?
Date: Sun, 12 Apr 2015 23:16:57 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin)

Dmitry Gutov <address@hidden> writes:

> On 04/12/2015 04:16 PM, address@hidden (João Távora) wrote:
>
>> As a side note, a spurious "Summary: " prefix slipped through in the
>> first line of the commit message, since I ammended my local commit from
>> the command line, with emacsclient as EDITOR and then used M-p
>> `log-edit-previous-comment' to pull in the last message. I saw
>> 'Summary:' fontified so assumed it would be killed by `log-edit-mode'.
>
> Thoughts:
>
> - I wonder why you didn't have the existing message already filled in
> the buffer, so you'd had to press `M-n'.

(I pressed `M-p', not `M-n'). But true, in recent tests I see always see
the last commit message when I commit --amend. Perhaps I had amended
some more times and wanted to go to some intermediate version.  I dunno
anymore.

> - This kind of commit message buffers should probably use a different
> major mode: after all, the format of the contents is different.

That's right. Although I can't resist asking why these "Summary" and
"Author" hints/cookies can't be some display-only element like a
before-string in an overlay. Why are they implemented as actual buffer
text?

> - vc-git supports the "amend" feature, so you shouldn't have had to
> use the command line; although it's a bit awkward when you want just
> to edit the message, and there are no changes in any files: then
> `vc-next-action' doesn't even initiate commit. We should integrate it
> with `log-view-modify-change-comment'.

Never tried it. Didn't know they existed even. I make commits from
vc-dir and command line alternately as is more convenient, so I
`log-edit-mode' in COMMIT_EDITMSG for a consistent UI.

> Maybe somewhere in `before-save-hook' of the new major mode?

Won't kick in when the buffer doesn't need saving. This seems works
nicely though:

    (defun log-edit--commit-editmsg-done ()
      ;; no idea why `log-edit-callback' is called with `call-interactive'
      (interactive)
      (save-excursion
        (goto-char (point-min))
        (when (and (search-forward-regexp "^Summary:[ \t]+" (line-end-position) 
t)
                   (y-or-n-p "Possibly spurious \"Summary:\" header detected. 
Remove?"))
          (delete-region (match-beginning 0) (match-end 0))))
      (save-buffer)
      (server-edit))
     
    (define-derived-mode log-edit--commit-editmsg-mode log-edit-mode "Log-Edit*"
      "Special version of `log-edit-mode' for .git/COMMIT_EDITMSG."
      (set (make-local-variable 'log-edit-callback)
           'log-edit--commit-editmsg-done)
      (setq default-directory (file-name-directory (directory-file-name 
default-directory))))
     
    (add-to-list 'auto-mode-alist '("\\.git/COMMIT_EDITMSG" . 
log-edit--commit-editmsg-mode))

Got it in my .emacs, but perhaps this could be installed, seems generic
enough. OTOH, git log --grep '^Summary:' seems to indicate this happens
only once every 5-6 years

João







reply via email to

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