Sometime I just want to go back to the place where I was entering text most recently. After browsing around in various files it’s sometimes a bit hard to remember the correct buffer-name and i start searching the buffer list for the correct name. Eclipse has something for this situation – and my emacs does have too, now:
(defvar mp/last-self-insert-command-buffer nil)
(defvar mp/last-self-insert-command-position nil)
(defun mp/last-self-insert-command-store ()
(interactive)
(let ((buffer (current-buffer)))
(when buffer
(setq mp/last-self-insert-command-buffer (current-buffer)
mp/last-self-insert-command-position (point)))))
(defadvice self-insert-command (after store-point-of-last-self-insert activate)
"Store buffer and buffer location where last self-insert-command happened."
(mp/last-self-insert-command))
(defun mp/goto-last-self-insert-command ()
(interactive)
(let ((window (get-buffer-window mp/last-self-insert-command-buffer t)))
(if window
(progn ;; buffer already has a window
(select-window window)
(goto-char mp/last-self-insert-command-position))
(progn ;; buffer has no window
(switch-to-buffer mp/last-self-insert-command-buffer)
(goto-char mp/last-self-insert-command-position)))))
(global-set-key (kbd "C-x C-q") 'mp/goto-last-self-insert-command)
The variable names look a bit clumsy. But this snipped has not yet reached version 1.0 😉 Beside that it’s working nice!
After collecting some opinions on Emacs reddit I re-engineered my snippet. It looks way more light now…
(defun mp/store-lot-position ()
(point-to-register ?z))
(defun mp/goto-lot-position ()
(interactive)
(jump-to-register ?z))
(add-hook 'post-self-insert-hook 'mp/store-lot-position)
(global-set-key (kbd "C-c q") 'mp/goto-lot-position)
Neueste Kommentare