From 76acb5b0615c77c63f46b51c46def7076f469170 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 19 Feb 2020 23:55:32 +0100 Subject: [PATCH] Emacs: Move register-navigation to (local) package. --- init.d/text/common.el | 57 +++++++++---------------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/init.d/text/common.el b/init.d/text/common.el index ca9a7f5..2e42603 100644 --- a/init.d/text/common.el +++ b/init.d/text/common.el @@ -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-" . my/prev-register) ; Jump to previous marker register. - ("C-" . my/next-register) ; Jump to next marker register. ("C-" . 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-" . register-quicknav/prev-register) + ("C-" . register-quicknav/next-register) + ("M-r" . register-quicknav/clear-current-register)) + ) + ;; Save cursor position. (use-package saveplace :config