Created
October 23, 2024 16:59
-
-
Save jamescherti/8921b341b628599ca8c7ff7f173a435a to your computer and use it in GitHub Desktop.
Emacs: Save point as a marker, window start/hscroll, restoring them after BODY.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; save-marker-and-window.el --- Emacs: Save point as a marker, window start/hscroll, restoring them after BODY. -*- lexical-binding: t; -*- | |
;; Gits URL: https://gist.github.com/jamescherti/8921b341b628599ca8c7ff7f173a435a | |
;; Usage: (my-save-marker-and-window (progn (your-code argument))) | |
;; License: MIT | |
;; Author: James Cherti | |
(defmacro my-save-marker-and-window (&rest body) | |
"Save point as a marker, window start/hscroll, restoring them after BODY." | |
`(let ((point-marker (copy-marker (point))) | |
(window-start-marker (copy-marker (window-start))) | |
(window-hscroll (window-hscroll))) | |
(unwind-protect | |
(progn ,@body) | |
(goto-char point-marker) | |
(set-window-start (selected-window) window-start-marker) | |
(set-window-hscroll (selected-window) window-hscroll)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment