settings.el 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. ;;; settings.el --- Miscellaneous settings
  2. ;; Copyright © 2012–2018 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. (require 'al-key)
  16. ;;; External processes
  17. (with-eval-after-load 'al-process
  18. (defun al/set-zathura-theme (name)
  19. (make-symbolic-link name (al/config-dir-file "zathura/theme") t))
  20. (defun al/sync-zathura-theme (&rest args)
  21. "Synchronize zathura theme with the current emacs theme."
  22. (when (al/process-is-program args "zathura")
  23. (al/set-zathura-theme
  24. (format "%S-theme" (frame-parameter nil 'background-mode)))))
  25. (al/add-hook-maybe 'al/before-process-functions
  26. 'al/sync-zathura-theme))
  27. (al/add-after-init-hook 'al/enable-process-hooks)
  28. ;;; Minibuffer, ido, smex
  29. (al/bind-key* "M-t" execute-extended-command)
  30. (setq enable-recursive-minibuffers t)
  31. (al/add-hook-maybe 'minibuffer-setup-hook 'al/hbar-cursor-type)
  32. (al/bind-keys-from-vars 'minibuffer-local-map 'al/minibuffer-keys)
  33. (when (require 'al-minibuffer nil t)
  34. (setq completing-read-function #'al/completing-read))
  35. (with-eval-after-load 'ido
  36. (setq
  37. ;; Not using virtual buffers because
  38. ;; `ido-add-virtual-buffers-to-list' blatantly enables
  39. ;; `recentf-mode'.
  40. ido-use-virtual-buffers nil
  41. ;; Disable auto searching for files unless called explicitly.
  42. ido-auto-merge-delay-time 999
  43. ido-enable-last-directory-history t
  44. ido-save-directory-list-file (al/emacs-data-dir-file "ido.last")
  45. ido-record-commands nil
  46. ido-enable-tramp-completion nil
  47. ido-enable-flex-matching t
  48. ido-create-new-buffer 'always
  49. ido-decorations
  50. '("\n─► " "" "\n " "\n ..." "[" "]" " [No match]" " [Matched]"
  51. " [Not readable]" " [Too big]" " [Confirm]" "\n─► " " ◄─"))
  52. (defconst al/ido-common-keys
  53. '(("C-l" . ido-toggle-ignore)
  54. ("C-M-l" . ido-toggle-regexp)
  55. ("C-." . ido-prev-match)
  56. ("C-e" . ido-next-match)
  57. ("<up>" . ido-prev-match)
  58. ("<down>" . ido-next-match)
  59. ("C-d" . ido-fallback-command)
  60. ("M-d" . ido-edit-input)
  61. ("M-k" . al/ido-copy-current-item)
  62. ("M-s" . ido-select-text)
  63. ;; C-j is unbound in `minibuffer-local-map'
  64. ("C-j" . ido-select-text)
  65. "SPC")
  66. "Alist of auxiliary keys for `ido-common-completion-map'.")
  67. (defconst al/ido-file-dir-keys
  68. '(("H-j" . ido-enter-dired)
  69. ("M-." . ido-prev-work-directory)
  70. ("M-e" . ido-next-work-directory)
  71. ("C-M-." . ido-prev-match-dir)
  72. ("C-M-e" . ido-next-match-dir)
  73. ("M-m" . ido-enter-magit-status)
  74. ("M-h" (al/ido-set-current-directory "~"))
  75. ("M-g" (al/ido-set-current-directory al/guix-profile-dir)))
  76. "Alist of auxiliary keys for `ido-file-dir-completion-map'.")
  77. (al/bind-keys-from-vars
  78. '(ido-common-completion-map
  79. ido-buffer-completion-map)
  80. '(al/minibuffer-keys al/ido-common-keys))
  81. (al/bind-keys-from-vars
  82. '(ido-file-dir-completion-map
  83. ido-file-completion-map)
  84. '(al/ido-file-dir-keys al/ido-common-keys))
  85. (al/add-hook-maybe 'ido-minibuffer-setup-hook 'al/no-truncate-lines)
  86. (ido-everywhere))
  87. (with-eval-after-load 'smex
  88. (setq
  89. smex-save-file (al/emacs-data-dir-file "smex-items")
  90. smex-history-length 32
  91. smex-prompt-string
  92. (concat (key-description (where-is-internal 'smex nil t))
  93. " (smex): "))
  94. (defun al/smex-prepare-ido-bindings ()
  95. "Add my bindings to the pseudo smex map."
  96. (let ((map ido-completion-map))
  97. (define-key map (kbd "C-h f") 'smex-describe-function)
  98. (define-key map (kbd "C-h w") 'smex-where-is)
  99. (define-key map (kbd "M-d") 'smex-find-function)
  100. (define-key map (kbd "C-d") 'smex-describe-function)))
  101. (advice-add 'smex-prepare-ido-bindings
  102. :override 'al/smex-prepare-ido-bindings))
  103. (with-eval-after-load 'ivy
  104. (setq
  105. ;; Since I don't use `ivy-mode' (as it sets
  106. ;; `completing-read-function'), set `completion-in-region-function'
  107. ;; manually.
  108. completion-in-region-function 'ivy-completion-in-region
  109. ;; Do not exit from minibuffer when there is nothing to delete.
  110. ivy-on-del-error-function 'ignore
  111. ivy-initial-inputs-alist nil
  112. ivy-sort-functions-alist nil
  113. ivy-sort-matches-functions-alist '((t . nil))
  114. ivy-sort-max-size 1000
  115. ivy-re-builders-alist '((t . ivy--regex-fuzzy))
  116. ivy-wrap t
  117. ivy-extra-directories nil)
  118. (defconst al/ivy-minibuffer-keys
  119. '(("TAB" . al/ivy-partial)
  120. ("RET" . ivy-alt-done)
  121. ("C-j" . ivy-immediate-done)
  122. ("C-l" . ivy-toggle-ignore)
  123. ("M-." . ivy-previous-history-element)
  124. ("M-e" . ivy-next-history-element)
  125. ("M-k" . al/ivy-copy-current-item))
  126. "Alist of auxiliary keys for `ivy-minibuffer-map'.")
  127. (al/bind-keys-from-vars 'ivy-minibuffer-map 'al/ivy-minibuffer-keys)
  128. (when (require 'al-ivy nil t)
  129. (setq ivy-format-function 'al/ivy-format-function)
  130. (push '(imenus . al/ivy-imenu-sort)
  131. ivy-sort-matches-functions-alist)
  132. (advice-add 'ivy-add-prompt-count
  133. :override 'al/ivy-add-prompt-count)))
  134. (with-eval-after-load 'counsel
  135. (define-key counsel-mode-map [remap switch-to-buffer]
  136. 'ivy-switch-buffer)
  137. (defconst al/counsel-describe-keys
  138. '(("M-d" . counsel-find-symbol))
  139. "Alist of auxiliary keys for `counsel-describe-map'.")
  140. (al/bind-keys-from-vars 'counsel-describe-map
  141. 'al/counsel-describe-keys)
  142. (defconst al/counsel-find-file-keys
  143. '(("M-h" (ivy--cd "~/"))
  144. ("M-m" . al/ivy-magit-status))
  145. "Alist of auxiliary keys for `counsel-find-file-map'.")
  146. (al/bind-keys-from-vars 'counsel-find-file-map
  147. 'al/counsel-find-file-keys)
  148. (when (require 'al-file nil t)
  149. (setq counsel-find-file-ignore-regexp
  150. (al/file-regexp "elc" "go"))))
  151. (al/eval-after-init
  152. (cond
  153. ((fboundp 'counsel-mode)
  154. (counsel-mode))
  155. ((fboundp 'smex)
  156. (al/bind-key "C-M-t" smex-major-mode-commands)
  157. (al/bind-key* "M-t" smex)))
  158. (unless (boundp 'ivy-mode)
  159. (ido-mode)))
  160. ;;; Working with buffers: ibuffer, uniquify, …
  161. (al/bind-keys*
  162. ("M-b" . mode-line-other-buffer)
  163. ("C-M-b" (find-file (al/notes-dir-file "bookmarks.org"))))
  164. (al/bind-keys*
  165. :prefix-map al/buffer-map
  166. :prefix-docstring "Map for managing/switching to buffers."
  167. :prefix "C-b"
  168. ("C-b" . al/switch-buffer)
  169. ("M-b" . ibuffer)
  170. ("r" . rename-buffer)
  171. ("c" . clone-buffer)
  172. ("n" . info)
  173. ("b" . al/buffer-name-to-kill-ring)
  174. ("f" . al/file-name-to-kill-ring)
  175. ("g" (al/display-buffer "*grep*"))
  176. ("o" (al/display-buffer "*Occur*"))
  177. ("h" (al/display-buffer "*Help*"))
  178. ("s" (al/display-buffer "*scratch*"))
  179. ("w" . al/switch-to-w3m)
  180. ("m" . woman)
  181. ("k" (kill-buffer nil))
  182. ("8" . al/switch-to-characters))
  183. (with-eval-after-load 'uniquify
  184. (setq uniquify-buffer-name-style 'post-forward))
  185. (with-eval-after-load 'ibuffer
  186. (setq ibuffer-default-sorting-mode 'filename/process)
  187. (defconst al/ibuffer-keys
  188. '(("u" . ibuffer-visit-buffer)
  189. ("." . ibuffer-backward-line)
  190. ("e" . ibuffer-forward-line)
  191. ("M-." . ibuffer-backward-filter-group)
  192. ("M-e" . ibuffer-forward-filter-group)
  193. ("d" . ibuffer-visit-buffer-other-window-noselect)
  194. ("C-d" . ibuffer-visit-buffer-other-window)
  195. ("C-l" (ibuffer-update t))
  196. ("z" . ibuffer-unmark-forward)
  197. ("Z" (ibuffer-unmark-all 0))
  198. ("* o" . ibuffer-mark-old-buffers))
  199. "Alist of auxiliary keys for `ibuffer-mode-map'.")
  200. (al/bind-keys-from-vars 'ibuffer-mode-map 'al/ibuffer-keys)
  201. (al/add-hook-maybe 'ibuffer-mode-hook
  202. '(al/mode-ibuffer-info hl-line-mode)))
  203. ;;; Working with windows and frames
  204. (setq split-width-threshold 120)
  205. (al/add-hook-maybe 'window-configuration-change-hook
  206. 'al/set-windows-num-property)
  207. ;; Open some buffers in the same window.
  208. (setq
  209. same-window-buffer-names
  210. '("*Apropos"
  211. "*Character List*"
  212. "*Character Set List*"
  213. "*Colors*"
  214. "*Diff*"
  215. "*Faces*"
  216. "*Google Translate*"
  217. "*Help*"
  218. "*Messages*"
  219. "*Occur*"
  220. "*Personal Keybindings*"
  221. "*Proced*"
  222. "*Process-Environment*"
  223. "*Process List*"
  224. "*Shadows*"
  225. "*YASnippet tables*")
  226. same-window-regexps
  227. '(".*\\.el\\.gz$"
  228. "shell\\*"))
  229. (al/bind-keys
  230. ("<H-XF86AudioRaiseVolume>" (enlarge-window 1 t))
  231. ("<H-XF86AudioLowerVolume>" (enlarge-window -1 t))
  232. ("<M-H-XF86AudioRaiseVolume>" (enlarge-window 1))
  233. ("<M-H-XF86AudioLowerVolume>" (enlarge-window -1))
  234. ("H-o" . al/other-window)
  235. ("H-M-o" . al/switch-or-next-window)
  236. ("H-M-q" (quit-window nil (previous-window)))
  237. ("H-O" . al/switch-to-minibuffer)
  238. ("H-1" . delete-other-windows)
  239. ("H-2" . al/make-vertical-windows)
  240. ("H-3" . al/make-horizontal-windows))
  241. (al/bind-keys
  242. :map ctl-x-map
  243. ("o" . al/other-window)
  244. ("M-o" . other-window))
  245. (setq
  246. winner-dont-bind-my-keys t
  247. winner-ring-size 40)
  248. (al/bind-keys
  249. ("<C-left>" . winner-undo)
  250. ("<C-right>" . winner-redo))
  251. (al/add-after-init-hook 'winner-mode)
  252. ;;; comint, shell, eshell
  253. (setq shell-file-name "bash")
  254. (al/bind-keys*
  255. :prefix-map al/repl-map
  256. :prefix-docstring "Map for various REPLs."
  257. :prefix "C-n"
  258. ("C-s" . shell)
  259. ("t" . visit-ansi-term)
  260. ("e" . eshell)
  261. ("i" . ielm)
  262. ("s" (al/sql-switch-or-connect 'darts))
  263. ("l" . slime-repl)
  264. ("g" . (lambda (arg) (interactive "P")
  265. (let (geiser-repl-use-other-window)
  266. (switch-to-guile arg))))
  267. ("G" . al/geiser-socket-connect)
  268. ("P" . run-python)
  269. ("p" . python-shell-switch-to-shell)
  270. ("L" . lua-start-process)
  271. ("m" . maxima)
  272. ("x" . guix-switch-to-repl))
  273. (with-eval-after-load 'comint
  274. (setq comint-move-point-for-output 'this
  275. comint-buffer-maximum-size 5000
  276. comint-password-prompt-regexp
  277. (rx-to-string `(or (and bol "Password")
  278. (regex ,comint-password-prompt-regexp))))
  279. (al/add-hook-maybe 'comint-output-filter-functions
  280. 'comint-truncate-buffer)
  281. (defconst al/comint-keys
  282. '(("M-." . comint-previous-input)
  283. ("M-e" . comint-next-input)
  284. ("M->" . comint-previous-prompt)
  285. ("M-E" . comint-next-prompt)
  286. ("C-c c" . compilation-shell-minor-mode)
  287. ("C-c o" . al/comint-toggle-move-point)
  288. ("C-c C-d" (process-send-eof))
  289. ("TAB" . completion-at-point)
  290. ("RET" . al/comint-send-input-maybe)
  291. "C-d")
  292. "Alist of auxiliary keys for comint modes.")
  293. (al/bind-keys-from-vars 'comint-mode-map 'al/comint-keys))
  294. (with-eval-after-load 'shell
  295. (defconst al/shell-keys
  296. '(("M-O" . shell-backward-command)
  297. ("M-U" . shell-forward-command))
  298. "Alist of auxiliary keys for `shell-mode-map'.")
  299. (al/bind-keys-from-vars 'shell-mode-map 'al/shell-keys t)
  300. (al/add-hook-maybe 'shell-mode-hook
  301. '(guix-build-log-minor-mode al/no-truncate-lines)))
  302. (al/bind-keys
  303. ("C-z" . eshell)
  304. ("C-M-z" . al/eshell-cd))
  305. (with-eval-after-load 'eshell
  306. (setq eshell-directory-name (al/emacs-data-dir-file "eshell"))
  307. (setq
  308. eshell-modules-list
  309. '(eshell-smart eshell-alias eshell-basic eshell-cmpl eshell-dirs
  310. eshell-glob eshell-hist eshell-ls eshell-pred eshell-prompt
  311. eshell-script eshell-term eshell-unix eshell-tramp)
  312. eshell-highlight-prompt nil
  313. eshell-hist-ignoredups t
  314. eshell-history-size 9999)
  315. (defconst al/eshell-keys
  316. '(("<M-tab>" . eshell-complete-lisp-symbol)
  317. ("RET" . al/eshell-send-input-maybe)
  318. ("C-a" . eshell-bol)
  319. ("C-k" . al/eshell-kill-whole-line)
  320. ("M-." . eshell-previous-input)
  321. ("M-e" . eshell-next-input)
  322. ("M->" . eshell-previous-prompt)
  323. ("M-E" . eshell-next-prompt)
  324. ("M-r" . al/eshell-previous-matching-input-from-input)
  325. ("M-s" . al/eshell-next-matching-input-from-input))
  326. "Alist of auxiliary keys for `eshell-mode'.")
  327. ;; For some strange reason `eshell-mode-map' is buffer local, so key
  328. ;; bindings should be put in a hook.
  329. (defun al/eshell-bind-keys ()
  330. (al/bind-keys-from-vars 'eshell-mode-map
  331. '(al/free-misc-keys al/eshell-keys)))
  332. ;; Default value of `paragraph-separate' breaks
  333. ;; `eshell-next-prompt'/`eshell-previous-prompt'.
  334. (defun al/eshell-set-paragraph ()
  335. (setq-local paragraph-separate "useLESS var"))
  336. (al/add-hook-maybe 'eshell-mode-hook
  337. '(al/eshell-bind-keys al/eshell-set-paragraph))
  338. (require 'tramp nil t)
  339. (when (require 'al-eshell nil t)
  340. (setq
  341. eshell-prompt-function 'al/eshell-prompt
  342. eshell-prompt-regexp al/eshell-prompt-regexp)
  343. (advice-add 'eshell/info :override 'al/eshell/info)))
  344. ;;; Button, custom, widget
  345. (with-eval-after-load 'button
  346. (defconst al/button-map-keys
  347. '(("u" . push-button))
  348. "Alist of auxiliary keys for `button-map'.")
  349. (al/bind-keys-from-vars 'button-map 'al/button-map-keys t)
  350. (al/bind-keys-from-vars 'button-buffer-map 'al/button-keys t))
  351. (with-eval-after-load 'wid-edit
  352. (defconst al/widget-button-keys
  353. '(("." . widget-backward)
  354. ("e" . widget-forward)
  355. ("u" . widget-button-press))
  356. "Alist of auxiliary keys for modes with widget buttons.")
  357. (defconst al/widget-field-keys
  358. '(("<M-tab>" . widget-complete)
  359. ("M-<" . widget-kill-line)
  360. ("<ctrl-i>" . widget-end-of-line)
  361. ("C-k" (beginning-of-line) (widget-kill-line)))
  362. "Alist of auxiliary keys for modes with widget fields.")
  363. (al/bind-keys-from-vars 'widget-keymap 'al/widget-button-keys t)
  364. (al/bind-keys-from-vars 'widget-field-keymap 'al/widget-field-keys))
  365. (with-eval-after-load 'cus-edit
  366. (al/bind-keys-from-vars 'custom-mode-map 'al/widget-button-keys t)
  367. (al/bind-keys
  368. :map custom-mode-map
  369. ("o" . Custom-goto-parent)
  370. ("g" . Custom-reset-standard)))
  371. ;;; Help, apropos, man, info
  372. (setq apropos-do-all t)
  373. (with-eval-after-load 'help
  374. (al/bind-keys
  375. :map help-map
  376. ("A" . apropos))
  377. (al/bind-keys
  378. :map help-map
  379. :prefix-map al/info-map
  380. :prefix-docstring "Map to display info manuals."
  381. :prefix "i"
  382. ("i" (info "dir"))
  383. ("c" (info "cl"))
  384. ("e" (info "elisp"))
  385. ("g" (info "guile"))
  386. ("x" (info "guix"))
  387. ("m" (info "make"))
  388. ("am" (info "automake"))
  389. ("ac" (info "autoconf"))
  390. ("t" (info "texinfo")))
  391. ;; Rebinding keys in `help-map' does not simply work: after evaluating
  392. ;; the code above, "C-h i" is still bound to `info'; resetting
  393. ;; `help-command' helps.
  394. (fset 'help-command help-map))
  395. (with-eval-after-load 'help-mode
  396. (al/bind-keys
  397. :map help-mode-map
  398. ("," . help-go-back)
  399. ("p" . help-go-forward))
  400. (al/add-hook-maybe 'help-mode-hook 'al/no-truncate-lines))
  401. (with-eval-after-load 'man
  402. (setq Man-notify-method 'pushy)
  403. (when (require 'al-file nil t)
  404. (setq Man-header-file-path
  405. (append (delq nil
  406. (mapcar (lambda (p)
  407. (al/file-if-exists
  408. (expand-file-name "include" p)))
  409. (al/guix-profiles)))
  410. Man-header-file-path)))
  411. (when (require 'al-mode-line nil t)
  412. (al/mode-line-default-buffer-identification 'Man-mode))
  413. (defconst al/man-keys
  414. '(("M->" . Man-previous-section)
  415. ("M-E" . Man-next-section)
  416. ("h" . Man-previous-section)
  417. ("n" . Man-next-section)
  418. ("m" . Man-goto-section)
  419. ("g" . Man-update-manpage))
  420. "Alist of auxiliary keys for `Man-mode'.")
  421. (al/bind-keys-from-vars 'Man-mode-map
  422. '(al/button-keys al/man-keys)))
  423. (with-eval-after-load 'woman
  424. (setq
  425. woman-fill-column (default-value 'fill-column)
  426. woman-default-indent 4)
  427. (defconst al/woman-keys
  428. '(("M-h" . WoMan-previous-manpage))
  429. "Alist of auxiliary keys for `woman-mode'.")
  430. (al/bind-keys-from-vars 'woman-mode-map 'al/woman-keys))
  431. (with-eval-after-load 'info
  432. ;; `Info-additional-directory-list' is USELESS as it is appended to
  433. ;; `Info-directory-list' (by `Info-find-file' or by
  434. ;; `Info-insert-dir'), so the default manuals are searched first,
  435. ;; while I want my dirs to be searched first.
  436. (info-initialize)
  437. (setq Info-directory-list
  438. (append (al/existing-files
  439. (al/emacs-my-packages-dir-file "guix/doc")
  440. (al/devel-dir-file "guix/doc"))
  441. Info-directory-list))
  442. (al/bind-keys
  443. :map Info-mode-map
  444. ("." . Info-prev-reference)
  445. ("e" . Info-next-reference)
  446. ("c" (Info-copy-current-node-name 0))
  447. ("o" (Info-up) (goto-char (point-min)))
  448. ("O" . Info-top-node)
  449. ("u" . Info-follow-nearest-node)
  450. ("," . Info-history-back)
  451. ("p" . Info-history-forward)
  452. ("y" . Info-history)
  453. ("k" . Info-index-next)
  454. ("h" . Info-prev)
  455. ("n" . Info-next)
  456. ("H" . Info-help)))
  457. (with-eval-after-load 'texinfo
  458. (require 'al-texinfo nil t)
  459. (defconst al/texinfo-keys
  460. '(("C-c c" . texinfo-insert-@code)
  461. ("C-c f" . texinfo-insert-@file)
  462. ("C-c i" . texinfo-insert-@item)
  463. ("C-c v" . texinfo-insert-@var)
  464. ("C-c M" . al/texinfo-insert-@menu)
  465. ("C-c E" . al/texinfo-insert-@example)
  466. ("C-c I" . al/texinfo-insert-@itemize)
  467. ("C-c T" . al/texinfo-insert-@table)
  468. ("C-c D" . al/texinfo-insert-@deffn))
  469. "Alist of auxiliary keys for `texinfo-mode'.")
  470. (al/bind-keys-from-vars 'texinfo-mode-map 'al/texinfo-keys))
  471. ;;; SQL
  472. (with-eval-after-load 'sql
  473. (setq
  474. sql-product 'postgres
  475. sql-database "darts"
  476. sql-user user-login-name
  477. sql-connection-alist
  478. `((darts (sql-product 'postgres)
  479. (sql-server "")
  480. (sql-database "darts")
  481. (sql-user ,user-login-name))))
  482. (defconst al/sql-keys
  483. '(("C-v" . sql-send-region)
  484. ("C-M-v" . sql-send-paragraph)
  485. ("M-s-v" . sql-send-buffer)
  486. ("C-c C-z" . al/sql-switch-to-repl))
  487. "Alist of auxiliary keys for `sql-mode'.")
  488. (al/bind-keys-from-vars 'sql-mode-map 'al/sql-keys)
  489. ;; I just can't stand the default key bindings.
  490. (al/clean-map 'sql-interactive-mode-map)
  491. (set-keymap-parent sql-interactive-mode-map comint-mode-map)
  492. (when (require 'al-sql nil t)
  493. (advice-add 'sql-highlight-product
  494. :override 'al/sql-highlight-product)
  495. (al/add-hook-maybe 'sql-mode-hook
  496. 'al/sql-set-comment-start-skip)
  497. (al/add-hook-maybe 'sql-interactive-mode-hook
  498. '(al/sql-save-history
  499. al/sql-highlight-product
  500. al/sql-completion-setup)))
  501. ;; Fix bug with mariadb prompt:
  502. ;; <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17426>.
  503. (sql-set-product-feature 'mysql :prompt-regexp
  504. "^\\(?:mysql\\|mariadb\\).*> "))
  505. (with-eval-after-load 'mysql
  506. (setq mysql-user sql-user)
  507. (when (require 'al-mysql nil t)
  508. (advice-add 'mysql-shell-query
  509. :override 'al/mysql-shell-query)))
  510. (with-eval-after-load 'sql-completion
  511. (setq
  512. sql-mysql-database sql-database
  513. sql-mysql-exclude-databases
  514. '("mysql" "information_schema" "performance_schema"))
  515. (require 'cl nil t))
  516. (with-eval-after-load 'al-sql
  517. (setq al/sql-history-dir (al/emacs-data-dir-file "sql")))
  518. ;;; Darts, journal
  519. (al/bind-keys
  520. :prefix-map al/darts-map
  521. :prefix-docstring "Map for darts and journal."
  522. :prefix "M-D"
  523. ("d" . darts-day-template)
  524. ("s" . darts-day-select)
  525. ("e" . darts-day-export)
  526. ("M-S M-D" . journal-search-by-date)
  527. ("M-S M-S" . journal-grep)
  528. ("j" . journal-create-entry)
  529. ("w" . journal-position-windows)
  530. ("c" . journal-change-created-property)
  531. ("v" . journal-change-converted-property)
  532. ("b" . journal-change-described-property)
  533. ("h" . journal-insert-subheading)
  534. ("H" . journal-back-to-entry-heading)
  535. ("i" . journal-insert-block)
  536. ("t" (find-file (al/journal-dir-file "tags"))))
  537. (with-eval-after-load 'journal
  538. (setq
  539. org-id-files (al/with-check
  540. :dir al/journal-dir
  541. (directory-files al/journal-dir t
  542. journal-file-name-regexp))
  543. org-id-locations-file (al/emacs-data-dir-file "org-id-locations")
  544. org-id-track-globally t
  545. org-agenda-files org-id-files
  546. journal-current-file (car (last org-id-files)))
  547. (setq
  548. journal-directory al/journal-dir
  549. journal-template-file (al/journal-dir-file "template"))
  550. (setq
  551. journal-open-block "┃"
  552. journal-close-block "┃")
  553. (defun al/journal-no-double-space ()
  554. (and (journal-buffer-p)
  555. (setq-local sentence-end-double-space nil)))
  556. (al/add-hook-maybe 'org-mode-hook 'al/journal-no-double-space))
  557. (al/autoload "darts-value"
  558. darts-throw-string-to-points
  559. darts-throw-string-to-code)
  560. (al/autoload "darts-daydata"
  561. darts-day-template
  562. darts-day-select)
  563. (with-eval-after-load 'darts-daydata
  564. :config
  565. (setq
  566. darts-database "darts"
  567. darts-data-dir "~/darts/daytables"
  568. darts-exported-dir (expand-file-name "exported" darts-data-dir)
  569. darts-template-file (expand-file-name "template" darts-data-dir)))
  570. ;;; Initial scratch and message buffers
  571. (setq
  572. initial-major-mode #'emacs-lisp-mode
  573. initial-buffer-choice #'messages-buffer
  574. message-log-max 5000)
  575. (defun al/set-scratch-message ()
  576. (setq initial-scratch-message
  577. (format (concat ";; Started: %s\n"
  578. ";; Init time: %s\n\n")
  579. (format-time-string "%d %B, %A %T" before-init-time)
  580. (emacs-init-time))))
  581. (defun al/reinit-messages-buffer ()
  582. "Initialize `messages-buffer-mode-hook' in a message buffer."
  583. (with-current-buffer (messages-buffer)
  584. (messages-buffer-mode)))
  585. (al/eval-after-init
  586. (al/set-scratch-message)
  587. (al/reinit-messages-buffer))
  588. (al/add-hook-maybe 'messages-buffer-mode-hook
  589. (list 'hl-todo-mode
  590. (lambda () (setq buffer-read-only nil))))
  591. ;;; Misc settings and packages
  592. (setq
  593. password-cache-expiry (* 24 60 60)
  594. line-number-display-limit-width 9999
  595. echo-keystrokes 0.2
  596. disabled-command-function nil
  597. inhibit-startup-screen t
  598. find-function-C-source-directory (al/src-dir-file "emacs-git/src"))
  599. ;; Do not pop up the *Warnings* buffer when something long is executed
  600. ;; in *shell*.
  601. (setq warning-suppress-types '((undo discard-info)))
  602. (electric-indent-mode 0)
  603. (advice-add 'yes-or-no-p :override 'y-or-n-p)
  604. (al/bind-keys-from-vars 'special-mode-map 'al/lazy-moving-keys t)
  605. (with-eval-after-load 'server
  606. (setq
  607. server-kill-new-buffers nil
  608. server-temp-file-regexp
  609. (concat server-temp-file-regexp
  610. "\\|COMMIT_EDITMSG\\|git-rebase-todo")))
  611. ;; Default value of `tramp-ssh-controlmaster-options' variable slows
  612. ;; down loading tramp significantly. This should be set before tramp
  613. ;; was loaded.
  614. (setq tramp-ssh-controlmaster-options "")
  615. (with-eval-after-load 'tramp-sh
  616. (push 'tramp-own-remote-path tramp-remote-path)
  617. (push "LC_ALL=en_US.UTF-8" tramp-remote-process-environment)
  618. (push "DISPLAY=:0" tramp-remote-process-environment))
  619. (with-eval-after-load 'gnutls
  620. ;; http://comments.gmane.org/gmane.emacs.gnus.general/83413
  621. (setq gnutls-min-prime-bits nil))
  622. (with-eval-after-load 'calc
  623. (setq calc-angle-mode 'rad))
  624. (with-eval-after-load 'picture
  625. (defconst al/picture-keys
  626. '(("M-O" . picture-movement-left)
  627. ("M-U" . picture-movement-right)
  628. ("M->" . picture-movement-up)
  629. ("M-E" . picture-movement-down)
  630. ("M-<" . picture-movement-nw)
  631. ("M-P" . picture-movement-ne)
  632. ("M-Q" . picture-movement-sw)
  633. ("M-K" . picture-movement-se))
  634. "Alist of auxiliary keys for `picture-mode-map'.")
  635. (al/bind-keys-from-vars 'picture-mode-map 'al/picture-keys))
  636. (with-eval-after-load 'artist
  637. (defconst al/artist-keys
  638. '(("C-o" . artist-backward-char)
  639. ("C-u" . artist-forward-char)
  640. ("C-." . artist-previous-line)
  641. ("C-e" . artist-next-line))
  642. "Alist of auxiliary keys for `artist-mode-map'.")
  643. (al/bind-keys-from-vars 'artist-mode-map 'al/artist-keys))
  644. (with-eval-after-load 'hexl
  645. (al/bind-keys
  646. :map hexl-mode-map
  647. ("C-." . hexl-previous-line)
  648. ("C-e" . hexl-next-line)
  649. ("C-o" . hexl-backward-char)
  650. ("C-u" . hexl-forward-char)
  651. ("M-o" . hexl-backward-short)
  652. ("M-u" . hexl-forward-short)
  653. ("C-i" . hexl-end-of-line)
  654. ("H-." . hexl-scroll-down)
  655. ("H-e" . hexl-scroll-up)
  656. ("H-a" . hexl-beginning-of-buffer)
  657. ("H-i" . hexl-end-of-buffer)))
  658. (with-eval-after-load 'diff-mode
  659. (defconst al/diff-shared-keys
  660. '(("." . diff-hunk-prev)
  661. (">" . diff-file-prev)
  662. ("e" . diff-hunk-next)
  663. ("E" . diff-file-next))
  664. "Alist of auxiliary keys for `diff-mode-shared-map'.")
  665. (defconst al/diff-keys
  666. '(("H-u" . diff-undo)
  667. ("M-." . diff-hunk-prev)
  668. ("M->" . diff-file-prev)
  669. ("M-e" . diff-hunk-next)
  670. ("M-E" . diff-file-next))
  671. "Alist of auxiliary keys for `diff-mode-map'.")
  672. (al/bind-keys-from-vars 'diff-mode-shared-map 'al/diff-shared-keys t)
  673. (al/bind-keys-from-vars 'diff-mode-map 'al/diff-keys))
  674. (with-eval-after-load 'ediff
  675. (when (require 'al-ediff nil t)
  676. (al/add-hook-maybe 'ediff-before-setup-hook
  677. 'al/ediff-save-window-configuration)
  678. (al/add-hook-maybe 'ediff-quit-hook
  679. 'al/ediff-restore-window-configuration
  680. t))
  681. (setq
  682. ediff-window-setup-function #'ediff-setup-windows-plain ; no new frame
  683. ediff-split-window-function #'split-window-horizontally
  684. ediff-grab-mouse nil)
  685. ;; The way `ediff-mode' works with the key bindings is even more evil
  686. ;; than `eshell-mode' does.
  687. (defconst al/ediff-keys
  688. '(("h" . ediff-previous-difference)
  689. ("H" . ediff-toggle-hilit))
  690. "Alist of auxiliary keys for `ediff-mode-map'.")
  691. (defun al/ediff-bind-keys ()
  692. (al/bind-keys-from-vars 'ediff-mode-map 'al/ediff-keys))
  693. (al/add-hook-maybe 'ediff-startup-hook 'al/ediff-bind-keys))
  694. (with-eval-after-load 'view
  695. (defconst al/view-keys
  696. '(("v" . View-exit))
  697. "Alist of auxiliary keys for `view-mode-map'.")
  698. (al/bind-keys-from-vars 'view-mode-map
  699. '(al/lazy-moving-keys al/view-keys)
  700. t))
  701. (with-eval-after-load 'epa
  702. (require 'wid-edit) ; for `al/widget-button-keys' (it is required anyway)
  703. (al/bind-keys-from-vars 'epa-key-list-mode-map
  704. 'al/widget-button-keys t)
  705. (al/bind-keys
  706. :map epa-key-list-mode-map
  707. ("z" . epa-unmark-key)))
  708. (al/bind-keys
  709. :prefix-map al/tags-map
  710. :prefix-docstring "Map for tags."
  711. :prefix "M-T"
  712. ("M-T" . find-tag)
  713. ("d" (find-tag (find-tag-default)))
  714. ("r" . find-tag-regexp)
  715. ("n" . tags-loop-continue)
  716. ("v" . visit-tags-table)
  717. ("c" . al/create-tags))
  718. (with-eval-after-load 'etags
  719. (setq tags-file-name (al/src-dir-file "conkeror/modules/TAGS")))
  720. (with-eval-after-load 'tabulated-list
  721. (defconst al/tabulated-list-keys
  722. '(("s" . tabulated-list-sort))
  723. "Alist of auxiliary keys for `tabulated-list-mode-map'.")
  724. (al/bind-keys-from-vars 'tabulated-list-mode-map
  725. '(al/lazy-moving-keys al/tabulated-list-keys)
  726. t)
  727. (add-hook 'tabulated-list-mode-hook 'hl-line-mode))
  728. (with-eval-after-load 'bui
  729. (defconst al/bui-keys
  730. '(("," . bui-history-back)
  731. ("p" . bui-history-forward))
  732. "Alist of auxiliary keys for `bui-map'.")
  733. (al/bind-keys-from-vars 'bui-map 'al/bui-keys))
  734. (with-eval-after-load 'bui-list
  735. (defconst al/bui-list-keys
  736. '(("u" . bui-list-describe)
  737. ("z" . bui-list-unmark)
  738. ("Z" . bui-list-unmark-all))
  739. "Alist of auxiliary keys for `bui-list-mode-map'.")
  740. (al/bind-keys-from-vars 'bui-list-mode-map 'al/bui-list-keys))
  741. ;;; settings.el ends here