Questions tagged [save-excursion]

20 questions
11
votes
1 answer

`looking-back` performance

I have some code using (looking-back … (line-beginning-position)). Doc string of looking-back states that it's better to avoid this function because of slowness. I'm curious will following approach be faster? (save-excursion (goto-char…
Geradlus_RU
  • 625
  • 7
  • 17
8
votes
2 answers

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

From the save-excursion docstring: Save point, mark, and current buffer; execute BODY; restore those things. My understanding was that the restored buffer would again be visible following the evaluation of the body, but that appears not to be the…
ebpa
  • 7,319
  • 26
  • 53
7
votes
4 answers

select text to end of line, without moving point

I often want to quickly mark everything from point to the end of line, leaving point at the same place. I tried to write simple function for that purpose: (defun mark-from-point-to-end-of-line () "Marks everything from point to end of line" …
Geradlus_RU
  • 625
  • 7
  • 17
5
votes
1 answer

(progn (scroll-up 1) (goto-char 0)) is different from (scroll-up 1) then (goto-char 0)

In any buffer, try to eval-expression the expression (scroll-up 1) and then eval (goto-char 0). The window scrolls up, then point is moved to the beginning of the buffer. Now, try eval-ing (progn (scroll-up 1) (goto-char 0)). Here, point is not…
jcarpenter2
  • 227
  • 1
  • 6
5
votes
1 answer

save-excursion and find-function-at-point

The find-function-at-point command finds a function and displays its definition in the other window, while moving point to the other window as well. I'd like to have a version of find-function-at-point that opens the function definition in the other…
Tianxiang Xiong
  • 3,848
  • 16
  • 27
4
votes
2 answers

Why save-excursion doesn't save point position?

I have the following code: (defun test-save-excursion () (interactive) (let ((buffer "*test*") (text "Lorem Ipsum is simply dummy text Lorem Ipsum has |been the industry's standard dummy text It was popularised in the 1960s")) …
Andrii Tykhonov
  • 452
  • 2
  • 13
3
votes
1 answer

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

I'm reading Emacs Lisp Intro by Robert J. Chassell. In 6.1 The ‘save-restriction’ Special Form when you use both ‘save-excursion’ and ‘save-restriction’, one right after the other, you should use ‘save-excursion’ outermost. If you write them in…
shynur
  • 4,065
  • 1
  • 3
  • 23
3
votes
2 answers

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

Say we have a org buffer with content: * top-level heading some text $ # $ denote cursor ** heading 3 ** heading 2 ** heading 1 ** heading 0 Now evaluate (save-excursion (org-sort-entries nil ?a)). The cursor goes to the beginning of…
Saddle Point
  • 481
  • 7
  • 23
3
votes
2 answers

How to move point to the end of another buffer, using `with-current-buffer` and `goto-char`?

I'm trying to implement «effective append» for log buffer, e.g. if a point is at point-max position then insert text and move point to new point-max, otherwise append text and preserve point position. I though this will be very trivial…
Geradlus_RU
  • 625
  • 7
  • 17
2
votes
1 answer

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

I wrote this function to basically bring my cursor back to the dired buffer, after opening the file in another window. This is so that I can scroll down the buffer, pressing o to keep previewing the files in the directory. However, after the…
Tian
  • 288
  • 1
  • 8
2
votes
1 answer

How to refresh org file programatically

I am using spacemacs-light theme in Emacs and love it. In my spacemacs-light theme, some org-files open with bullets not hidden though. In those cases I go to the top of the file and hit C-c C-c to refresh my org-file. And then I go back to where I…
Ugur
  • 139
  • 1
  • 6
2
votes
1 answer

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

Here is the official definition of copy-to-buffer in Emacs 26.1 (the doc string part is omitted for brevity) (defun copy-to-buffer (buffer start end) (interactive "BCopy to buffer: \nr") (let ((oldbuf (current-buffer))) (with-current-buffer…
nalzok
  • 665
  • 6
  • 18
1
vote
0 answers

Does markdown-export have a bad interaction with save-excursion

I am trying to write an idle-timer to export my markdown file whenever I am idle. (I have the output loaded in a Chrome tab which is auto-reloading.) I tried to do the following: (defvar my--markdown-idle-timer nil) (defvar…
Troy Daniels
  • 487
  • 2
  • 13
1
vote
1 answer

Why does point move after executing this function from keybinding

I have the following line in my init.el: (define-key org-mode-map (kbd "C-c C-p") (lambda () (interactive) (org-publish-project "publish-website")) ) The "publish-website" argument points to an element of my org-publish-project-alist. …
User12345
  • 145
  • 4
0
votes
0 answers

`run-python` cannot hide *Python* buffer

When running (defun my/run-python () (interactive) (let ((buf (current-buffer))) (with-current-buffer buf (save-mark-and-excursion (run-python (python-shell-calculate-command) nil nil) ) )) ) I…
phoxd
  • 231
  • 1
  • 7
1
2