Emacs: Move register-navigation to (local) package.
This commit is contained in:
parent
03acc522a6
commit
76acb5b061
|
@ -1,6 +1,6 @@
|
|||
;;; common.el --- Common settings for text files. -*- lexical-binding: t; -*-
|
||||
|
||||
;; Time-stamp: <2020-02-19T15:56:29+0100>
|
||||
;; Time-stamp: <2020-02-19T16:47:39+0100>
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
|
@ -16,62 +16,27 @@
|
|||
(fill-column 80) ; Documents are 80 chars wide by default.
|
||||
(word-wrap t) ; Wrap at word for continuation lines.
|
||||
|
||||
:config
|
||||
(defvar my/current-marker-register 0
|
||||
"An index to the current marker register.")
|
||||
|
||||
(defun my/sort-marker-register-elements (a b)
|
||||
"Returns `t' if the file name is the same and A < B."
|
||||
(and (string= (buffer-file-name (marker-buffer (cdr a)))
|
||||
(buffer-file-name (marker-buffer (cdr b))))
|
||||
(< (marker-position (cdr a))
|
||||
(marker-position (cdr b)))))
|
||||
|
||||
(defun my/marker-registers ()
|
||||
"Returns all registers which markers."
|
||||
(let (result)
|
||||
(dolist (item register-alist)
|
||||
(when (markerp (cdr item))
|
||||
(setq result (cons item result))))
|
||||
(sort result 'my/sort-marker-register-elements)))
|
||||
|
||||
(defun my/next-register ()
|
||||
"Jump to next register."
|
||||
(interactive)
|
||||
(setq my/current-marker-register (+ my/current-marker-register 1))
|
||||
(when (>= my/current-marker-register (length (my/marker-registers)))
|
||||
(setq my/current-marker-register 0))
|
||||
(let (register-element register-name)
|
||||
(setq register-element
|
||||
(car (nthcdr my/current-marker-register (my/marker-registers))))
|
||||
(setq register-name (car register-element))
|
||||
(register-to-point register-name)))
|
||||
|
||||
(defun my/prev-register ()
|
||||
"Jump to previous register."
|
||||
(interactive)
|
||||
(setq my/current-marker-register (- my/current-marker-register 1))
|
||||
(when (< my/current-marker-register 0)
|
||||
(setq my/current-marker-register (- (length (my/marker-registers)) 1)))
|
||||
(let (register-element register-name)
|
||||
(setq register-element
|
||||
(car (nthcdr my/current-marker-register (my/marker-registers))))
|
||||
(setq register-name (car register-element))
|
||||
(register-to-point register-name)))
|
||||
|
||||
:bind
|
||||
("C-r" . jump-to-register) ; Move point to location in register.
|
||||
("C-S-r" . point-to-register) ; Store location of point in register.
|
||||
("M-W" . copy-to-register) ; Store text in register.
|
||||
("C-S-y" . insert-register) ; Insert text from register.
|
||||
("C-<f5>" . my/prev-register) ; Jump to previous marker register.
|
||||
("C-<f6>" . my/next-register) ; Jump to next marker register.
|
||||
("C-<f7>" . list-registers) ; List all registers.
|
||||
|
||||
:hook
|
||||
(text-mode . auto-fill-mode) ; Enable word-wrapping at fill-column.
|
||||
)
|
||||
|
||||
;; Quickly jump to next/previous register.
|
||||
(use-package register-quicknav
|
||||
:ensure nil ; Local package.
|
||||
:commands (register-quicknav/prev-register
|
||||
register-quicknav/next-register)
|
||||
:bind (("C-<f5>" . register-quicknav/prev-register)
|
||||
("C-<f6>" . register-quicknav/next-register)
|
||||
("M-r" . register-quicknav/clear-current-register))
|
||||
)
|
||||
|
||||
;; Save cursor position.
|
||||
(use-package saveplace
|
||||
:config
|
||||
|
|
Loading…
Reference in New Issue
Block a user