Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; If the buffer is narrowed, the normal mapping of M-g g calls
- ;; `goto-line', which widens the buffer. Default behavior reguires the
- ;; user to remember to call `goto-line-relative'. This function honors
- ;; narrowing, if in place. Binding to M-g g lets the user have normal
- ;; work flow without being concerned with narrow/wide status.
- (defun goto-line-dwim (line)
- "Go to line, do what I mean. Call `goto-line' or
- `goto-line-relative', depending on whether the buffer is narrowed or
- not. Honors the current line number display setting for the buffer."
- (interactive "p")
- (let ((line-numbers display-line-numbers-mode))
- (unless line-numbers
- (display-line-numbers-mode 1))
- (unwind-protect
- (call-interactively #'goto-line-relative)
- (unless line-numbers
- (display-line-numbers-mode -1)))))
- (global-set-key (kbd "M-g g") #'goto-line-dwim)
Advertisement
Add Comment
Please, Sign In to add comment