system-manager-wakasu
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 casual-bookmarks
121 :bind (:map bookmark-bmenu-mode-map
122 ("C-o" . casual-bookmarks-tmenu)
123 ("S" . casual-bookmarks-sortby-tmenu)
124 ("J" . bookmark-jump))
125 :after (bookmark))
126
127(keymap-global-set "S-<down-mouse-2>" 'strokes-do-stroke)
128
129(use-package repeat
130 :config
131 (setq repeat-on-final-keystroke t)
132 (setq set-mark-command-repeat-pop t)
133
134 (repeat-mode 1)
135
136 (defvar isearch-repeat-map
137 (let ((map (make-sparse-keymap)))
138 (define-key map (kbd "s") #'isearch-repeat-forward)
139 (define-key map (kbd "r") #'isearch-repeat-backward)
140 map))
141
142 (dolist (cmd '(isearch-repeat-forward isearch-repeat-backward))
143 (put cmd 'repeat-map 'isearch-repeat-map))
144
145 (defvar buffer-navigation-map
146 (let ((map (make-sparse-keymap)))
147 (define-key map (kbd "n") #'next-line)
148 (define-key map (kbd "p") #'previous-line)
149 (define-key map (kbd "f") #'forward-word)
150 (define-key map (kbd "b") #'backward-word)
151 (define-key map (kbd "u") #'scroll-up-command)
152 (define-key map (kbd "d") #'scroll-down-command)
153 map))
154
155 (dolist (cmd '(next-line previous-line forward-word backward-word scroll-up-command scroll-down-command))
156 (put cmd 'repeat-map 'buffer-navigation-map)))
157
158(require 'view)
159
160(add-hook
161 'view-mode-hook
162 (lambda ()
163 (cond ((derived-mode-p 'org-mode)
164 (define-key view-mode-map (kbd "p") 'org-previous-visible-heading)
165 (define-key view-mode-map (kbd "n") 'org-next-visible-heading))
166 ((derived-mode-p 'markdown-mode)
167 (define-key view-mode-map (kbd "p") 'markdown-outline-previous)
168 (define-key view-mode-map (kbd "n") 'markdown-outline-next))
169 ((derived-mode-p 'html-mode)
170 (define-key view-mode-map (kbd "p") 'sgml-skip-tag-backward)
171 (define-key view-mode-map (kbd "n") 'sgml-skip-tag-forward))
172 ((derived-mode-p 'python-mode)
173 (define-key view-mode-map (kbd "p") 'python-nav-backward-block)
174 (define-key view-mode-map (kbd "n") 'python-nav-forward-block))
175 ((derived-mode-p 'emacs-lisp-mode)
176 (define-key view-mode-map (kbd "p") 'backward-sexp)
177 (define-key view-mode-map (kbd "n") 'forward-sexp))
178 ((derived-mode-p 'makefile-mode)
179 (define-key view-mode-map (kbd "p") 'makefile-previous-dependency)
180 (define-key view-mode-map (kbd "n") 'makefile-next-dependency))
181 ((derived-mode-p 'c-mode)
182 (define-key view-mode-map (kbd "p") 'c-beginning-of-defun)
183 (define-key view-mode-map (kbd "n") 'c-end-of-defun))
184 (t
185 (define-key view-mode-map (kbd "p") 'scroll-down-command)
186 (define-key view-mode-map (kbd "n") 'scroll-up-command)))))
187
188(use-package outline-indent
189 :custom
190 (outline-indent-ellipsis " ▼ ")
191 :config
192 (add-hook 'yaml-mode-hook #'outline-indent-minor-mode)
193 (add-hook 'yaml-ts-mode-hook #'outline-indent-minor-mode))
194
195(provide 'config-navigating)
196;;; config-navigating.el ends here