1

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. This works as expected, except that it moves my point to the start of the buffer when I execute it (which is very annoying). I have two questions (thanks in advance for your help):

  1. What am I doing wrong here?
  2. How do I fix it?

1 Answer 1

3

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 ()
    (interactive)
    (save-excursion
      (org-publish-project "publish-website"))))

save-excursion is a macro that saves the point and the current buffer, runs the code you provided, then restores point and the current buffer to the saved values.

2
  • save-excursion is exactly what I needed; elisp has so many nice built-in functions I don't know about :)
    – User12345
    Aug 22, 2020 at 18:40
  • 1
    There are certainly quite a lot of them. There are a few other save-foo macros you might go look up as well.
    – db48x
    Aug 22, 2020 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.