git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] git-blame.el: Do not use goto-line in lisp code

From
Lawrence Mitchell <wence@gmx.li>
Date
Jun 14, 2012, 09:14 UTC
Message-ID
<87k3za9rwj.fsf@gmx.li>
In-Reply-To
<20120614050854.GG27586@burratino>
Jonathan Nieder wrote:
> Hi Lawrence,
> Lawrence Mitchell wrote:
>> From: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
>> goto-line is a user-level command, instead use the lisp-level
>> construct recommended in Emacs documentation.
> [...]
>> Here we go, all Rüdiger's changes look sensible, I've split them into bits though
> Thanks for looking them over.
> Would you mind indulging my curiosity a little by describing what bad
> behavior or potential bad behavior this change prevents?

goto-line sets the mark, and respects the variable selective-display. It also widens the buffer before moving to the relevant line. The first two are almost never what you'd want in lisp code, the latter you'd probably want to make explicit in the calls I guess.

the with-current-buffer issue is a bit more subtle, and I realise my patch for this didn't actually fix the bug, or describe the problem properly (reroll to come).

Basically:

save-excursion saves point, mark and current-buffer in the buffer in scope when it is called, but if we do:

(save-excursion
  (set-buffer buf)
  ;; modify point and mark in buf
  ...)

hoping to save point and mark in buf, it doesn't happen. Instead, we need to make buf current before calling save-excursion. And we want to restore the value of current-buffer in scope at the beginning of the call afterward, hence the correct idiom is:

(with-current-buffer buf
  (save-excursion ...))
Cheers,
Lawrence
-- 
Lawrence Mitchell <wence@gmx.li>
Previous: Jonathan NiederNext: Lawrence Mitchell
Message 15 of 18 in “git-blame.el: Fix compilation warnings.”
  1. git-blame.el: Fix compilation warnings.Rüdiger Sonderfeld, Jan 12, 2012
  2. Jonathan NiederJan 12, 2012
  3. Rüdiger SonderfeldJan 12, 2012
  4. Sending patches with KMail (Re: [PATCH] git-blame.el: Fix compilation warnings.)Jonathan Nieder, Jan 13, 2012
  5. Junio C HamanoJan 14, 2012
  6. Jonathan NiederJan 14, 2012
  7. Jonathan NiederJan 14, 2012
  8. Junio C HamanoJan 15, 2012
  9. Rüdiger SonderfeldJan 14, 2012
  10. git-blame.el: use mapc instead of mapcarJonathan Nieder, Jun 10, 2012
  11. 1/3 git-blame.el: Do not use goto-line in lisp codeLawrence Mitchell, Jun 10, 2012
  12. 2/3 git-blame.el: Use with-current-buffer where appropriateLawrence Mitchell, Jun 10, 2012
  13. 3/3 git-blame.el: Do not use bare 0 to mean (point-min)Lawrence Mitchell, Jun 10, 2012
  14. Jonathan NiederJun 14, 2012
  15. Lawrence MitchellJun 14, 2012
  16. 1/3 git-blame.el: Do not use goto-line in lisp codeLawrence Mitchell, Jun 14, 2012
  17. 2/3 git-blame.el: Use with-current-buffer where appropriateLawrence Mitchell, Jun 14, 2012
  18. 3/3 git-blame.el: Do not use bare 0 to mean (point-min)Lawrence Mitchell, Jun 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.