text.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. ;;; text.el --- Working with text: editing, searching, …
  2. ;; Copyright © 2014–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. ;;; Global keys for moving
  17. (al/bind-keys
  18. ("C-o" . backward-char)
  19. ("M-o" . backward-word)
  20. ("C-M-o" . backward-sexp)
  21. ("M-O" . backward-sentence)
  22. ("C-H-M-o" (scroll-right 1))
  23. ("C-u" . forward-char)
  24. ("M-u" . forward-word)
  25. ("C-M-u" . forward-sexp)
  26. ("M-U" . forward-sentence)
  27. ("C-H-M-u" (scroll-left 1))
  28. ("C-." . previous-line)
  29. ("M-." . backward-paragraph)
  30. ("C-M-." . backward-up-list)
  31. ("M->" . backward-page)
  32. ("C-H-M-." (scroll-down 1))
  33. ("H-." . scroll-down-command)
  34. ("H-M-." . scroll-other-window-down)
  35. ("s-." . al/previous-link)
  36. ("C-e" . next-line)
  37. ("M-e" . forward-paragraph)
  38. ("C-M-e" . down-list)
  39. ("M-E" . forward-page)
  40. ("C-H-M-e" (scroll-up 1))
  41. ("H-e" . scroll-up-command)
  42. ("H-M-e" . scroll-other-window)
  43. ("s-e" . al/next-link)
  44. ("C-M-a" . beginning-of-defun)
  45. ("M-A" . al/beginning-of-line)
  46. ("H-a" . beginning-of-buffer)
  47. ("C-M-i" . end-of-defun)
  48. ("M-I" . al/end-of-line)
  49. ("H-i" . end-of-buffer)
  50. ("C-3" . recenter-top-bottom)
  51. ("C-H-3" . al/recenter-top)
  52. ("C-2" . move-to-window-line-top-bottom))
  53. (if al/mwim-exists?
  54. (al/bind-keys
  55. ("C-a" . mwim-beginning)
  56. ("<ctrl-i>" . mwim-end))
  57. (al/bind-keys
  58. ("C-a" . beginning-of-line)
  59. ("<ctrl-i>" . end-of-line)))
  60. (unless (display-graphic-p)
  61. (al/bind-keys
  62. ("M-." . previous-line)
  63. ("M-e" . next-line)
  64. ("M->" . scroll-down-command)
  65. ("M-E" . scroll-up-command)
  66. ("C-x a" . beginning-of-buffer)
  67. ("C-x i" . end-of-buffer)
  68. ("C-M-i" . complete-symbol))
  69. (if al/mwim-exists?
  70. (al/bind-keys
  71. ("M-a" . mwim-beginning)
  72. ("M-i" . mwim-end))
  73. (al/bind-keys
  74. ("M-a" . beginning-of-line)
  75. ("M-i" . end-of-line))))
  76. (al/bind-keys
  77. :map narrow-map
  78. ("r" . narrow-to-region))
  79. ;;; Global keys for editing
  80. (al/bind-keys
  81. ("C-," . delete-char)
  82. ("M-," . kill-word)
  83. ("C-M-," . kill-sexp)
  84. ("M-<" . kill-line)
  85. ("H-M-," . al/delete-blank-lines)
  86. ("C-p" . delete-backward-char)
  87. ("M-p" . backward-kill-word)
  88. ("C-M-p" . backward-kill-sexp)
  89. ("M-P" . al/backward-kill-line)
  90. ("H-M-p" . delete-trailing-whitespace)
  91. ("C-M-q" . al/save-sexp)
  92. ("M-Q" . al/save-line)
  93. ("C-k" . kill-whole-line)
  94. ("M-k" . al/save-whole-line)
  95. ("C-M-k" . al/backward-save-sexp)
  96. ("M-K" . al/backward-save-line)
  97. ("H-k" . al/duplicate-dwim)
  98. ("C-'" . transpose-chars)
  99. ("M-'" (transpose-words -1))
  100. ("C-M-'" . transpose-sexps)
  101. ("M-\"" . transpose-lines)
  102. ("C-;" . open-line)
  103. ("M-;" . al/comment-dwirm)
  104. ("C-M-;" . split-line)
  105. ("C-t" . kill-region)
  106. ("M-x" . kill-ring-save)
  107. ("C-M-x" . append-next-kill)
  108. ("S-SPC" . just-one-space)
  109. ("M-S-SPC" . al/delete-horizontal-space)
  110. ("M-SPC" . mark-word)
  111. ("M-s-SPC" . mark-paragraph)
  112. ("C-M-s-SPC" . mark-defun)
  113. ("H-s-SPC" . mark-whole-buffer)
  114. ("C-y" . al/yank-or-prev)
  115. ("M-y" . al/yank-or-next)
  116. ("C-M-y" . al/insert-clipboard)
  117. ("C-j" . newline-and-indent)
  118. ("M-J" (delete-indentation -1))
  119. ("<S-backspace>" . delete-region)
  120. ("H-M-a" . align-regexp)
  121. ("C-H-M-a" (align-regexp (region-beginning) (region-end)
  122. "\\(\\s-*\\)(("))
  123. ("M-%" . ispell-complete-word)
  124. ("M-_" . shift-number-down)
  125. ("M-+" . shift-number-up)
  126. ("M-/" . dabbrev-expand)
  127. ("C-M-/" . hippie-expand)
  128. ("M-?" . al/dabbrev-expand-word)
  129. ("<C-kanji>" . al/downcase-word-backward)
  130. ("<S-kanji>" . al/capitalize-word-backward)
  131. ("<H-kanji>" . al/upcase-word-backward)
  132. ("<C-M-kanji>" . al/downcase-dwim)
  133. ("<M-S-kanji>" . al/capitalize-dwim)
  134. ("<H-M-kanji>" . al/upcase-dwim))
  135. (al/bind-keys
  136. ("<M-tab>" . complete-symbol) ; shadows "\M-\t" ("C-M-i") in any mode, so be careful
  137. ("<C-tab>" . indent-relative)
  138. ("<M-S-iso-lefttab>" . tab-to-tab-stop)
  139. ("<H-tab>" . indent-region)
  140. ("C-c u" . al/decode-region))
  141. ;;; Global keys for inserting text
  142. (define-key key-translation-map [?\C--] [?–])
  143. (define-key key-translation-map [?\C-\M--] [?—])
  144. (al/bind-keys
  145. ("C->" (insert "->"))
  146. ("H-4" . insert-parentheses)
  147. ("H-5" . insert-pair-square-brackets)
  148. ("H-6" . insert-pair-curly-brackets)
  149. ("H-," . insert-pair-angle-brackets)
  150. ("H-;" . insert-pair-single-quotations)
  151. ("H-'" . insert-pair-double-quotations)
  152. ("C-H-," . insert-pair-angle-quotations)
  153. ("C-H-;" . insert-pair-left-right-single-quotations)
  154. ("C-H-'" . insert-pair-left-right-double-quotations)
  155. ("H-`" . insert-pair-grave-accent-quotation)
  156. ("C-H-`" . insert-pair-grave-accents))
  157. (al/bind-keys
  158. :prefix-map al/insert-map
  159. :prefix-docstring "Map for inserting symbols and text."
  160. :prefix "M-i"
  161. ("M-i" . al/insert-delimiter)
  162. ("M-a" (insert ";;;###autoload\n"))
  163. ("t" (insert "TODO"))
  164. ("f" (insert "FIXME"))
  165. ("d" . al/insert-date)
  166. ("M-'" . insert-pair-top-corners)
  167. ("M-;" . insert-pair-bottom-corners))
  168. ;;; Searching, finding and replacing
  169. (al/bind-keys
  170. :map search-map
  171. ("s" . query-replace)
  172. ("M-s" . query-replace)
  173. ("r" . query-replace-regexp)
  174. ("R" . replace-regexp))
  175. (setq
  176. isearch-allow-scroll t
  177. isearch-lax-whitespace nil)
  178. (al/bind-keys
  179. :map isearch-mode-map
  180. ("M-s" . isearch-query-replace)
  181. ("M-d" . isearch-edit-string)
  182. ("M-o" . isearch-occur)
  183. ("s-7" (al/set-isearch-input-method nil))
  184. ("s-8" (al/set-isearch-input-method "dvorak-russian-computer")))
  185. (defconst al/occur-keys
  186. '(("." . occur-prev)
  187. ("e" . occur-next)
  188. ("u" . occur-mode-goto-occurrence))
  189. "Alist of auxiliary keys for `occur-mode-map'.")
  190. (al/bind-keys-from-vars 'occur-mode-map 'al/occur-keys)
  191. (defun al/occur-set-paragraph ()
  192. "Set paragraph to be started from any non-space symbol."
  193. (setq-local paragraph-start "[^ ]"))
  194. (al/add-hook-maybe 'occur-mode-hook 'al/occur-set-paragraph)
  195. (with-eval-after-load 'grep
  196. (setq grep-save-buffers nil))
  197. (with-eval-after-load 'misearch
  198. (setq multi-isearch-pause nil))
  199. (al/bind-keys
  200. :prefix-map al/point-pos-map
  201. :prefix-docstring "Map for point-pos."
  202. :prefix "M-Z"
  203. ("M-S" . point-pos-save)
  204. ("M-D" . point-pos-delete)
  205. ("M-G" . point-pos-goto)
  206. ("M-H" . point-pos-previous)
  207. ("M-N" . point-pos-next)
  208. ("s" . point-pos-save)
  209. ("d" . point-pos-delete)
  210. ("g" . point-pos-goto)
  211. ("h" . point-pos-previous)
  212. ("n" . point-pos-next))
  213. (al/bind-keys
  214. ("C-M-S-g" . point-pos-goto)
  215. ("C-M-S-h" . point-pos-previous)
  216. ("C-M-S-n" . point-pos-next))
  217. (al/bind-key* "C-M-s-m" imenu)
  218. (with-eval-after-load 'imenu
  219. (setq imenu-space-replacement nil))
  220. (al/bind-key* "C-M-m" imenus)
  221. (with-eval-after-load 'imenus
  222. (setq imenus-delimiter " ⇨ ")
  223. (defconst al/imenus-keys
  224. '(("C-r" . imenus-rescan)
  225. ("C-s" . imenus-exit-to-isearch)
  226. ("M-s" . imenus-exit-to-occur)))
  227. (al/bind-keys-from-vars 'imenus-minibuffer-map 'al/imenus-keys)
  228. (when (require 'al-imenus nil t)
  229. (setq imenus-completing-read-function 'al/imenus-completing-read)))
  230. (al/bind-key "s-s" al/imenus-search-elisp-directories)
  231. (with-eval-after-load 'al-imenus
  232. (setq al/imenus-elisp-directories
  233. (list al/emacs-init-dir al/emacs-utils-dir)))
  234. ;;; Killing and yanking
  235. (setq
  236. mark-ring-max 30
  237. set-mark-command-repeat-pop t
  238. mouse-yank-at-point t
  239. kill-do-not-save-duplicates t
  240. mouse-drag-copy-region t
  241. select-active-regions nil)
  242. ;; Use PRIMARY instead of CLIPBOARD.
  243. (setq select-enable-primary t
  244. select-enable-clipboard nil)
  245. (al/bind-key "C-H-y" browse-kill-ring)
  246. (with-eval-after-load 'browse-kill-ring
  247. (setq
  248. browse-kill-ring-separator (make-string 64 ?—)
  249. browse-kill-ring-separator-face nil)
  250. (defconst al/browse-kill-ring-keys
  251. '(("." . browse-kill-ring-previous)
  252. ("e" . browse-kill-ring-forward)
  253. ("u" . browse-kill-ring-insert-and-quit)
  254. ("M-d" . browse-kill-ring-edit))
  255. "Alist of auxiliary keys for `browse-kill-ring-mode-map'.")
  256. ;; The keys are defined inside `browse-kill-ring-mode'.
  257. (defun al/browse-kill-ring-bind-keys ()
  258. (al/bind-keys-from-vars 'browse-kill-ring-mode-map
  259. 'al/browse-kill-ring-keys t))
  260. (al/add-hook-maybe 'browse-kill-ring-mode-hook
  261. 'al/browse-kill-ring-bind-keys))
  262. (with-eval-after-load 'register
  263. (setq register-preview-delay 0.3)
  264. (defun al/insert-register-reverse-arg (fun register &optional arg)
  265. "Reverse the meaning of ARG for `insert-register'."
  266. (funcall fun register (not arg)))
  267. (advice-add 'insert-register
  268. :around #'al/insert-register-reverse-arg))
  269. ;;; Misc settings and packages
  270. (setq-default
  271. major-mode 'text-mode
  272. truncate-lines t
  273. indent-tabs-mode nil
  274. fill-column 72)
  275. (setq
  276. save-abbrevs nil
  277. dabbrev-abbrev-char-regexp "\\sw\\|[-_+*]")
  278. (setq parens-require-spaces nil)
  279. ;; Smooth scrolling.
  280. (setq
  281. mouse-wheel-scroll-amount '(3 ((shift) . 1))
  282. mouse-wheel-progressive-speed nil
  283. scroll-conservatively 111
  284. auto-window-vscroll nil
  285. next-screen-context-lines 3
  286. scroll-preserve-screen-position t)
  287. (prefer-coding-system 'utf-8)
  288. (al/add-hook-maybe 'after-save-hook 'al/check-parens)
  289. (al/modify-syntax text-mode-syntax-table (?\" "\" "))
  290. (al/add-hook-maybe 'text-mode-hook
  291. '(visual-line-mode
  292. abbrev-mode
  293. al/no-syntactic-font-lock
  294. al/show-trailing-whitespace))
  295. (with-eval-after-load 'mwim
  296. (defun al/mwim-set-default (var fun)
  297. (set var
  298. (cl-substitute-if
  299. `(t . ,fun)
  300. (lambda (assoc) (eq t (car assoc)))
  301. (symbol-value var))))
  302. (al/mwim-set-default 'mwim-beginning-of-line-function
  303. 'beginning-of-visual-line)
  304. (al/mwim-set-default 'mwim-end-of-line-function
  305. 'end-of-visual-line))
  306. (with-eval-after-load 'abbrev
  307. (define-abbrev-table 'global-abbrev-table
  308. '(("gos" "GuixSD")
  309. ("hhg" "GNU/Linux")
  310. ("hhpr" "programming")
  311. ("hhy" "yesterday")
  312. ("hhY" "Yesterday")
  313. ("hh1" "Monday")
  314. ("hh2" "Tuesday")
  315. ("hh3" "Wednesday")
  316. ("hh4" "Thursday")
  317. ("hh5" "Friday")
  318. ("hh6" "Saturday")
  319. ("hh7" "Sunday"))))
  320. (define-key key-translation-map [?\M-i] 'iso-transl-ctl-x-8-map)
  321. (with-eval-after-load 'iso-transl
  322. ;; Expand "C-x 8" (now "M-i") map:
  323. (iso-transl-define-keys
  324. '(("a" . [?α])
  325. ("b" . [?β])
  326. ("g" . [?γ])
  327. ("l" . [?λ])
  328. ("p" . [?π])
  329. ("i" . [?∞])
  330. ("r" . [?√])
  331. ("A" . [?∀])
  332. ("E" . [?∃])
  333. ("nE" . [?∄])
  334. ("e" . [?∈])
  335. ("ne" . [?∉])
  336. ([?\C-0] . [?∅])
  337. ("NN" . [?ℕ])
  338. ("NZ" . [?ℤ])
  339. ("NQ" . [?ℚ])
  340. ("NR" . [?ℝ])
  341. ("NC" . [?ℂ])
  342. ("s" . [?☺])
  343. ("S" . [?☹])
  344. ("=" . [?≈])
  345. ("' " . [?′])
  346. ("\" " . [?″])
  347. ("/12" . [?½])
  348. ("/13" . [?⅓])
  349. ("/23" . [?⅔])
  350. ("/14" . [?¼])
  351. ("/34" . [?¾])
  352. ([?\C-.] . [?·])
  353. ("<" . [?≤])
  354. (">" . [?≥])
  355. ("." . [?…])
  356. ([?\M-v] . [?✓])
  357. ([?\M-x] . [?✗])
  358. ([?\C-u] . [?↔])
  359. ([?\C-o] . [?⇆])
  360. ([?\M-.] . [?↑])
  361. ([?\M-e] . [?↓])
  362. ([?\M-o] . [?←])
  363. ([?\M-u] . [?→])
  364. ([?\C-\M-.] . [?⇑])
  365. ([?\C-\M-e] . [?⇓])
  366. ([?\C-\M-o] . [?⇐])
  367. ([?\C-\M-u] . [?⇒])))
  368. ;; "M-i <N>" to insert superscript numbers.
  369. ;; "M-i M-<N>" to insert subscript numbers.
  370. (defun al/make-number-alist (numbers &optional modifier)
  371. (cl-loop for i to 9
  372. for char across numbers
  373. collect (cons (kbd (concat modifier
  374. (number-to-string i)))
  375. (vector char))))
  376. (iso-transl-define-keys
  377. (append
  378. (al/make-number-alist "⁰¹²³⁴⁵⁶⁷⁸⁹")
  379. (al/make-number-alist "₀₁₂₃₄₅₆₇₈₉" "M-"))))
  380. (with-eval-after-load 'pcomplete
  381. ;; Although `pcomplete-suffix-list' is marked as obsolete, it is used
  382. ;; by `pcomplete-insert-entry', and its default value prevents
  383. ;; inserting space after ":" (while completing ERC nicks).
  384. (setq pcomplete-suffix-list nil)
  385. (when (require 'al-pcomplete nil t)
  386. (al/add-hook-maybe '(shell-mode-hook eshell-mode-hook)
  387. 'al/pcomplete-no-space)))
  388. (with-eval-after-load 'pcmpl-args
  389. (setq
  390. pcmpl-args-debug-parse-help t
  391. pcmpl-args-cache-default-duration 999999
  392. pcmpl-args-cache-max-duration pcmpl-args-cache-default-duration))
  393. (al/bind-key "<C-H-tab>" company-complete)
  394. (al/autoload "company" company-complete)
  395. (with-eval-after-load 'company
  396. (setq
  397. company-idle-delay nil
  398. company-show-numbers t)
  399. (al/bind-keys
  400. :map company-active-map
  401. ("M-." . company-select-previous)
  402. ("M-e" . company-select-next))
  403. (global-company-mode))
  404. ;;; Yasnippet
  405. (al/autoload "yasnippet"
  406. yas-new-snippet
  407. yas-insert-snippet)
  408. (setq
  409. al/my-snippets-dir (al/emacs-data-dir-file "snippets/my")
  410. al/yas-snippets-dir (al/emacs-data-dir-file "snippets/yas")
  411. ;; al/yas-snippets-dir (expand-file-name "yasnippet/snippets"
  412. ;; quelpa-build-dir)
  413. yas-snippet-dirs (list al/my-snippets-dir al/yas-snippets-dir)
  414. yas-prompt-functions '(yas-ido-prompt))
  415. ;; I do not use `yas-minor-mode' (or `yas-global-mode') because I don't
  416. ;; want to see `yas--post-command-handler' in `post-command-hook'. I
  417. ;; just use yas functionality when I need to expand something without
  418. ;; enabling the mode.
  419. (al/bind-keys
  420. ("<kanji>" . al/yas-next-field-or-expand)
  421. ("<M-kanji>" . al/yas-exit-and-expand))
  422. (al/bind-keys
  423. :prefix-map al/yas-map
  424. :prefix-docstring "Map for yasnippet commands."
  425. :prefix "M-Y"
  426. ("M-Y" . yas-insert-snippet)
  427. ("f" . yas-visit-snippet-file)
  428. ("r" (yas--load-pending-jits))
  429. ("R" . yas-reload-all)
  430. ("n" . yas-new-snippet)
  431. ("l" . yas-load-directory)
  432. ("d" . yas-describe-tables)
  433. ("g" . yas-global-mode)
  434. ("s" (al/find-file
  435. (expand-file-name "yasnippet/snippets/emacs-lisp-mode"
  436. quelpa-build-dir))))
  437. (with-eval-after-load 'yasnippet
  438. (setq yas-indent-line 'fixed)
  439. (setq yas-new-snippet-default "\
  440. # -*- mode: snippet; require-final-newline: nil -*-
  441. # contributor: Alex Kost
  442. # name: $1
  443. # key: $1
  444. # --
  445. $0")
  446. ;; Allow any editing during working with a snippet.
  447. (advice-add 'yas--on-protection-overlay-modification
  448. :override 'ignore)
  449. (al/bind-key "C-g" ((yas-exit-all-snippets) (keyboard-quit)))
  450. (al/bind-keys
  451. :map yas-minor-mode-map
  452. ("<tab>") ("TAB"))
  453. (al/bind-keys
  454. :map yas-keymap
  455. ("<kanji>" . yas-next-field-or-maybe-expand)
  456. ("<S-kanji>" . yas-prev-field)
  457. ("M-<" . yas-skip-and-clear-or-delete-char)
  458. ("C-d") ("C-g") ("<tab>") ("TAB"))
  459. (al/bind-keys
  460. :map snippet-mode-map
  461. ("C-c C-k" (kill-buffer nil)))
  462. (yas--load-snippet-dirs)
  463. (yas--load-pending-jits))
  464. ;;; Working with parentheses (paredit, smartparens)
  465. (al/autoload "paredit"
  466. paredit-reindent-defun
  467. paredit-newline
  468. paredit-backward-kill-word
  469. paredit-forward-kill-word
  470. paredit-backward
  471. paredit-forward
  472. paredit-backward-up
  473. paredit-forward-down
  474. paredit-kill
  475. paredit-splice-sexp
  476. paredit-splice-sexp-killing-backward
  477. paredit-splice-sexp-killing-forward
  478. paredit-raise-sexp
  479. paredit-forward-slurp-sexp
  480. paredit-forward-barf-sexp
  481. paredit-backward-slurp-sexp
  482. paredit-backward-barf-sexp
  483. paredit-split-sexp
  484. paredit-join-sexps)
  485. (with-eval-after-load 'paredit
  486. (al/clean-map 'paredit-mode-map)
  487. (al/bind-keys
  488. :map paredit-mode-map
  489. ("<H-M-tab>" . paredit-reindent-defun)
  490. ("C-j" . paredit-newline)
  491. ("M-p" . paredit-backward-kill-word)
  492. ("M-," . paredit-forward-kill-word)
  493. ("C-M-o" . paredit-backward)
  494. ("C-M-u" . paredit-forward)
  495. ("C-M-." . paredit-backward-up)
  496. ("C-M-e" . paredit-forward-down)
  497. ("M-<" . paredit-kill)
  498. ("H-E" . paredit-splice-sexp)
  499. ("H-P" . paredit-splice-sexp-killing-backward)
  500. ("H-<" . paredit-splice-sexp-killing-forward)
  501. ("H->" . paredit-raise-sexp)
  502. ("C-)" . paredit-forward-slurp-sexp)
  503. ("C-M-0" . paredit-forward-barf-sexp)
  504. ("C-(" . paredit-backward-slurp-sexp)
  505. ("C-M-9" . paredit-backward-barf-sexp)
  506. ("C-M-5" . paredit-split-sexp)
  507. ("C-M-6" . paredit-join-sexps))
  508. (add-to-list 'emulation-mode-map-alists
  509. `((paredit-mode . ,paredit-mode-map))))
  510. (al/autoload "smartparens"
  511. sp-indent-defun
  512. sp-backward-kill-word
  513. sp-kill-word
  514. sp-backward-sexp
  515. sp-forward-sexp
  516. sp-backward-up-sexp
  517. sp-down-sexp
  518. sp-splice-sexp
  519. sp-splice-sexp-killing-forward
  520. sp-splice-sexp-killing-backward
  521. sp-splice-sexp-killing-around
  522. sp-backward-kill-sexp
  523. sp-backward-copy-sexp
  524. sp-kill-sexp
  525. sp-copy-sexp
  526. sp-transpose-sexp
  527. sp-forward-slurp-sexp
  528. sp-forward-barf-sexp
  529. sp-backward-slurp-sexp
  530. sp-backward-barf-sexp)
  531. (with-eval-after-load 'smartparens
  532. (require 'smartparens-config nil t)
  533. (setq
  534. sp-navigate-reindent-after-up nil
  535. sp-ignore-modes-list nil
  536. sp-wrap-entire-symbol 'globally
  537. ;; It should be anything!!!!
  538. sp-navigate-consider-stringlike-sexp '(latex-mode))
  539. (al/bind-keys
  540. :map smartparens-mode-map
  541. ("<H-M-tab>" . sp-indent-defun)
  542. ("M-p" . sp-backward-kill-word)
  543. ("M-," . sp-kill-word)
  544. ("C-M-o" . sp-backward-sexp)
  545. ("C-M-u" . sp-forward-sexp)
  546. ("C-M-." . sp-backward-up-sexp)
  547. ("C-M-e" . sp-down-sexp)
  548. ("H-E" . sp-splice-sexp)
  549. ("H-<" . sp-splice-sexp-killing-forward)
  550. ("H-P" . sp-splice-sexp-killing-backward)
  551. ("H->" . sp-splice-sexp-killing-around)
  552. ("C-M-p" . sp-backward-kill-sexp)
  553. ("C-M-k" . sp-backward-copy-sexp)
  554. ("C-M-," . sp-kill-sexp)
  555. ("C-M-q" . sp-copy-sexp)
  556. ("C-M-'" . sp-transpose-sexp)
  557. ("C-)" . sp-forward-slurp-sexp)
  558. ("C-M-0" . sp-forward-barf-sexp)
  559. ("C-(" . sp-backward-slurp-sexp)
  560. ("C-M-9" . sp-backward-barf-sexp))
  561. (al/bind-keys
  562. :map smartparens-mode-map
  563. :prefix-map al/smartparens-map
  564. :prefix-docstring "Map for misc smartparens commands."
  565. :prefix "H-p"
  566. ("c" . sp-cheat-sheet)
  567. ("." . sp-absorb-sexp)
  568. ("e" . sp-emit-sexp)
  569. ("o" . sp-convolute-sexp)
  570. ("j" . sp-join-sexp)
  571. ("s" . sp-split-sexp)))
  572. (when (and (fboundp 'smartparens-mode)
  573. (fboundp 'paredit-mode))
  574. (al/bind-key "H-p H-p" al/parens-mode)
  575. (defvar al/parens-mode-map (make-sparse-keymap))
  576. (al/bind-keys
  577. :map al/parens-mode-map
  578. ("<H-M-tab>" . sp-indent-defun)
  579. ("M-p" . paredit-backward-kill-word)
  580. ("M-," . paredit-forward-kill-word)
  581. ("C-M-." . paredit-backward-up)
  582. ("C-M-e" . paredit-forward-down)
  583. ("H-E" . paredit-splice-sexp)
  584. ("H-P" . paredit-splice-sexp-killing-backward)
  585. ("H-<" . paredit-splice-sexp-killing-forward)
  586. ("H->" . paredit-raise-sexp)
  587. ("C-M-p" . al/backward-kill-sexp)
  588. ("C-M-," . al/kill-sexp)
  589. ("C-M-'" . sp-transpose-sexp)
  590. ("C-)" . sp-forward-slurp-sexp)
  591. ("C-M-0" . sp-forward-barf-sexp)
  592. ("C-(" . sp-backward-slurp-sexp)
  593. ("C-M-9" . sp-backward-barf-sexp))
  594. (al/bind-keys
  595. :map al/parens-mode-map
  596. :prefix-map al/parens-misc-map
  597. :prefix-docstring "Map for misc parens commands."
  598. :prefix "H-p"
  599. ("c" . sp-cheat-sheet)
  600. ("." . sp-absorb-sexp)
  601. ("e" . sp-emit-sexp)
  602. ("o" . sp-convolute-sexp)
  603. ("j" . sp-join-sexp)
  604. ("s" . sp-split-sexp))
  605. (define-minor-mode al/parens-mode
  606. "Minor mode for working with parentheses."
  607. :init-value nil
  608. :lighter " ()")
  609. (defconst al/parens-ignore-modes
  610. '(c-mode c++-mode ; because of "<H-M-tab>" (better ideas?)
  611. nxml-mode)
  612. "List of modes where `al/parens-mode' should not be enabled.")
  613. (defun al/turn-on-parens-mode ()
  614. (unless (or (apply #'derived-mode-p al/parens-ignore-modes)
  615. (boundp 'ido-completing-read)) ; inside ido
  616. (al/parens-mode)))
  617. (define-globalized-minor-mode al/global-parens-mode
  618. al/parens-mode al/turn-on-parens-mode)
  619. (al/global-parens-mode))
  620. ;;; text.el ends here