Skip to main content
8 votes
Accepted

save-excursion doesn't restore the currently visible buffer?

The current buffer need not be visible in a window. You're looking for save-window-excursion (or quite possibly a combination of the two). n.b. C-uC-ha ^save- will point out all of the following: ...
phils's user avatar
  • 51.7k
6 votes
Accepted

How to refresh org file programatically

You're on the right track, but the standard elisp idiom for "go somewhere else in the buffer, do some stuff, and then go back to where you came from" is to use save-excursion. You can ...
Dan's user avatar
  • 33.1k
4 votes

save-excursion does not work with `org-sort-entries`

This post provides a work-around, but not an answer to "why does save-excursion not work here?" The problem is interesting. I find org internals to be baroque, and a skim through the source code for ...
Dan's user avatar
  • 33.1k
4 votes

save-excursion doesn't restore the currently visible buffer?

Facing a similar problem, I realize this behavior is due to find-file in particular. I didn't try using save-window-excursion instead of save-excursion. What I used instead was (with-current-buffer (...
George Moutsopoulos's user avatar
3 votes

What's the point of `save-excursion` twice in `copy-to-buffer`?

Why do you think so? with-current-buffer does not do a save-excursion. Its purpose is just to temporarily change the current buffer (i.e., set it to some buffer and at the end restore what was the ...
Drew's user avatar
  • 78k
3 votes
Accepted

Why does point move after executing this function from keybinding

You're not doing anything wrong, but org-publish probably is. However, you can fix the problem by using save-excursion: (define-key org-mode-map (kbd "C-c C-p") (lambda () (...
db48x's user avatar
  • 18.4k
3 votes
Accepted

Save excursion not working for dired-find-file-other-window

You don't need to write a custom function this time. You're looking for dired-display-file, bound to C-o.
aadcg's user avatar
  • 1,248
2 votes
Accepted

Why does this function (that uses save-excursion) leave me at another buffer

You're probably looking for save-window-excursion. Note the docstring warnings; but as org-id-goto uses pop-to-buffer-same-window which will use the current window unless called from a minibuffer or ...
phils's user avatar
  • 51.7k
1 vote
Accepted

Put “save-excursion” Outermost When Using Both “save-excursion” And “save-restriction”

The Emacs Lisp Reference Manual says: ‘save-restriction’ does _not_ restore point; use ‘save-excursion’ for that. If you use both ‘save-restriction’ and ‘save-excursion’ together, ‘...
NickD's user avatar
  • 30.8k
1 vote
Accepted

Function to undo point excursion

I think your first idea is the best: ... (goto-char (let ((pt (point))) (save-excursion (if BODY (point) pt))))) You ...
NickD's user avatar
  • 30.8k
1 vote
Accepted

How to deal with unwanted cursor movement during logic test

further to my comment on your own answer something like this makes more sense to me as the check doesnt alter anything. (defun next-pair-exists-in (func) "Check if inner or outer pair ...
RichieHH's user avatar
  • 873
1 vote

save-excursion does not work with `org-sort-entries`

One idea would be to record the headline and search for it to get back there again at the end (but this example will find the last occurrence if there are duplicate headings in the same file): (let ...
lawlist's user avatar
  • 19.2k

Only top scored, non community-wiki answers of a minimum length are eligible