config-navigating.el (6556B)
1 ;;; config-navigating.el --- -*- lexical-binding: t -*- 2 ;;; Commentary: 3 ;;; Navigation related configuration 4 ;;; Code: 5 6 (use-package emacs 7 :config 8 (setq-default scroll-preserve-screen-position t) 9 (setq-default scroll-conservatively 1) ; affects `scroll-step' 10 (setq-default scroll-margin 0) 11 12 (define-minor-mode vde/scroll-centre-cursor-mode 13 "Toggle centred cursor scrolling behaviour." 14 :init-value nil 15 :lighter " S=" 16 :global nil 17 (if vde/scroll-centre-cursor-mode 18 (setq-local scroll-margin (* (frame-height) 2) 19 scroll-conservatively 0 20 maximum-scroll-margin 0.5) 21 (dolist (local '(scroll-preserve-screen-position 22 scroll-conservatively 23 maximum-scroll-margin 24 scroll-margin)) 25 (kill-local-variable `,local)))) 26 27 ;; C-c l is used for `org-store-link'. The mnemonic for this is to 28 ;; focus the Line and also works as a variant of C-l. 29 :bind ("C-c L" . vde/scroll-centre-cursor-mode)) 30 31 (use-package replace 32 :config 33 (setq list-matching-lines-jump-to-current-line t) 34 ;; See my "Modus themes" for these inherited faces 35 (setq list-matching-lines-buffer-name-face 36 '(:inherit modus-theme-intense-neutral :weight bold)) 37 (setq list-matching-lines-current-line-face 38 '(:inherit modus-theme-special-mild)) 39 40 (defun vde/occur-url () 41 "Produce list with all URLs in the current buffer." 42 (interactive) 43 (let ((urls browse-url-button-regexp)) 44 (occur urls "\\&"))) 45 46 :hook ((occur-mode . hl-line-mode) 47 (occur-mode . (lambda () 48 (toggle-truncate-lines t)))) 49 :bind (("M-s M-o" . multi-occur) 50 :map occur-mode-map 51 ("t" . toggle-truncate-lines))) 52 53 (use-package avy 54 :unless noninteractive 55 :commands (avy-goto-char avy-goto-line avy-goto-word-1 avy-pop-mark avy-goto-char-timer) 56 :bind (("C-c j w" . avy-goto-word-1) 57 ("C-c j b" . avy-pop-mark) 58 ("C-c j t" . avy-goto-char-timer) 59 ("C-c j l" . avy-goto-line) 60 (:map isearch-mode-map ("C-j" . avy-isearch))) 61 :config 62 (defun avy-action-helpful (pt) 63 (save-excursion 64 (goto-char pt) 65 (helpful-at-point)) 66 (select-window 67 (cdr (ring-ref avy-ring 0))) 68 t) 69 70 (setf (alist-get ?H avy-dispatch-alist) 'avy-action-helpful)) 71 72 (use-package casual-avy 73 :unless noninteractive 74 :bind ("C-c j j" . casual-avy-tmenu)) 75 76 (use-package mwim 77 :unless noninteractive 78 :commands (mwim-beginning-of-code-or-line mwim-end-of-code-or-line) 79 :bind (:map prog-mode-map 80 ("C-a" . mwim-beginning-of-code-or-line) 81 ("C-e" . mwim-end-of-code-or-line))) 82 83 (use-package beginend 84 :unless noninteractive 85 :defer 5 86 :config 87 (beginend-global-mode 1)) 88 89 (use-package imenu 90 :unless noninteractive 91 :config 92 (setq-default imenu-use-markers t 93 imenu-auto-rescan t 94 imenu-auto-rescan-maxout 600000 95 imenu-max-item-length 100 96 imenu-use-popup-menu nil 97 imenu-eager-completion-buffer t 98 imenu-space-replacement " " 99 imenu-level-separator "/") 100 101 :hook ((imenu-after-jump . (lambda () 102 (when (and (eq major-mode 'org-mode) 103 (org-at-heading-p)) 104 (org-show-entry) 105 (org-reveal t)))))) 106 107 (use-package flimenu 108 :unless noninteractive 109 :config 110 (flimenu-global-mode 1)) 111 112 (use-package man 113 :unless noninteractive 114 :commands (man) 115 :bind (:map Man-mode-map 116 ("i" . Man-goto-section) 117 ("g" . Man-update-manpage))) 118 119 (use-package bookmark+) 120 (use-package bookmark) 121 (use-package casual-bookmarks 122 :bind (:map bookmark-bmenu-mode-map 123 ("C-o" . casual-bookmarks-tmenu) 124 ("S" . casual-bookmarks-sortby-tmenu) 125 ("J" . bookmark-jump)) 126 :after (bookmark)) 127 128 (keymap-global-set "S-<down-mouse-2>" 'strokes-do-stroke) 129 130 (use-package repeat 131 :config 132 (setq repeat-on-final-keystroke t) 133 (setq set-mark-command-repeat-pop t) 134 135 (repeat-mode 1) 136 137 (defvar isearch-repeat-map 138 (let ((map (make-sparse-keymap))) 139 (define-key map (kbd "s") #'isearch-repeat-forward) 140 (define-key map (kbd "r") #'isearch-repeat-backward) 141 map)) 142 143 (dolist (cmd '(isearch-repeat-forward isearch-repeat-backward)) 144 (put cmd 'repeat-map 'isearch-repeat-map)) 145 146 (defvar buffer-navigation-map 147 (let ((map (make-sparse-keymap))) 148 (define-key map (kbd "n") #'next-line) 149 (define-key map (kbd "p") #'previous-line) 150 (define-key map (kbd "f") #'forward-word) 151 (define-key map (kbd "b") #'backward-word) 152 (define-key map (kbd "u") #'scroll-up-command) 153 (define-key map (kbd "d") #'scroll-down-command) 154 map)) 155 156 (dolist (cmd '(next-line previous-line forward-word backward-word scroll-up-command scroll-down-command)) 157 (put cmd 'repeat-map 'buffer-navigation-map))) 158 159 (require 'view) 160 161 (add-hook 162 'view-mode-hook 163 (lambda () 164 (cond ((derived-mode-p 'org-mode) 165 (define-key view-mode-map (kbd "p") 'org-previous-visible-heading) 166 (define-key view-mode-map (kbd "n") 'org-next-visible-heading)) 167 ((derived-mode-p 'markdown-mode) 168 (define-key view-mode-map (kbd "p") 'markdown-outline-previous) 169 (define-key view-mode-map (kbd "n") 'markdown-outline-next)) 170 ((derived-mode-p 'html-mode) 171 (define-key view-mode-map (kbd "p") 'sgml-skip-tag-backward) 172 (define-key view-mode-map (kbd "n") 'sgml-skip-tag-forward)) 173 ((derived-mode-p 'python-mode) 174 (define-key view-mode-map (kbd "p") 'python-nav-backward-block) 175 (define-key view-mode-map (kbd "n") 'python-nav-forward-block)) 176 ((derived-mode-p 'emacs-lisp-mode) 177 (define-key view-mode-map (kbd "p") 'backward-sexp) 178 (define-key view-mode-map (kbd "n") 'forward-sexp)) 179 ((derived-mode-p 'makefile-mode) 180 (define-key view-mode-map (kbd "p") 'makefile-previous-dependency) 181 (define-key view-mode-map (kbd "n") 'makefile-next-dependency)) 182 ((derived-mode-p 'c-mode) 183 (define-key view-mode-map (kbd "p") 'c-beginning-of-defun) 184 (define-key view-mode-map (kbd "n") 'c-end-of-defun)) 185 (t 186 (define-key view-mode-map (kbd "p") 'scroll-down-command) 187 (define-key view-mode-map (kbd "n") 'scroll-up-command))))) 188 189 190 (provide 'config-navigating) 191 ;;; config-navigating.el ends here