Advertisement
mark-naylor-1701

goto line, do what I mean

Oct 21st, 2023 (edited)
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.67 KB | None | 0 0
  1. ;; If the buffer is narrowed, the normal mapping of M-g g calls
  2. ;; `goto-line', which widens the buffer. Default behavior reguires the
  3. ;; user to remember to call `goto-line-relative'. This function honors
  4. ;; narrowing, if in place. Binding to M-g g lets the user have normal
  5. ;; work flow without being concerned with narrow/wide status.
  6.  
  7. (defun goto-line-dwim (line)
  8.   "Go to line, do what I mean. Call `goto-line' or
  9. `goto-line-relative', depending on whether the buffer is narrowed
  10. or not."
  11.   (interactive "p")
  12.   (call-interactively
  13.    (if (not (buffer-narrowed-p))
  14.        #'goto-line
  15.      #'goto-line-relative)))
  16.  
  17. (global-set-key (kbd "M-g g") #'goto-line-dwim)
  18.  
Tags: elisp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement