text.el 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. (setq rotate-text-symbols
  2. '(("define" "define*" "define-public")
  3. ("private" "protected" "public")
  4. ("android-ndk-build-system" "ant-build-system"
  5. "asdf-build-system" "cargo-build-system" "clojure-build-system"
  6. "cmake-build-system" "dub-build-system" "dune-build-system"
  7. "emacs-build-system" "font-build-system"
  8. "glib-or-gtk-build-system" "gnu-build-system" "go-build-system"
  9. "guile-build-system" "haskell-build-system"
  10. "linux-module-build-system" "meson-build-system"
  11. "minify-build-system" "ocaml-build-system" "perl-build-system"
  12. "python-build-system" "rakudo-build-system" "r-build-system"
  13. "ruby-build-system" "scons-build-system" "texlive-build-system"
  14. "trivial-build-system" "waf-build-system")))
  15. (setq highlight-indent-guides-method 'character)
  16. ;; TODO: Implement wi-soften-hardlines
  17. ;; Origin <https://lists.gnu.org/archive/html/emacs-devel/2017-12/msg00518.html>.
  18. ;; See also <https://github.com/legoscia/messages-are-flowing>.
  19. ;; (defun wi-soften-hardlines ()
  20. ;; (interactive)
  21. ;; (save-excursion
  22. ;; (goto-char (point-min))
  23. ;; (mail-text)
  24. ;; (while (search-forward hard-newline nil t)
  25. ;; (replace-match "\n"))))
  26. (defun wi-sort-sexps (reverse beg end)
  27. "Sort sexps in the Region."
  28. (interactive "*P\nr")
  29. (save-restriction
  30. (narrow-to-region beg end)
  31. (goto-char (point-min))
  32. (let ((nextrecfun (lambda () (skip-syntax-forward "-.>")))
  33. (endrecfun #'forward-sexp))
  34. (sort-subr reverse nextrecfun endrecfun))))
  35. (defun wi-find-stumpwm-init-file ()
  36. "Edit the `stumpwm-init-file', in another window."
  37. (interactive)
  38. (find-file-other-window
  39. (expand-file-name "~/.stumpwm.d/init.lisp")))
  40. (defun wi-copy-file-name ()
  41. "Return current buffer file name."
  42. (interactive)
  43. (kill-new (buffer-file-name)))
  44. (defun wi-copy-project-file-name ()
  45. "Return current buffer file name in current project."
  46. (interactive)
  47. (kill-new (file-relative-name (buffer-file-name)
  48. (funcall (cl-find-if 'fboundp
  49. '(projectile-project-root
  50. vc-root-dir))))))
  51. ;; Origin <https://emacs.stackexchange.com/a/2473>.
  52. (defun wi-dabbrev-expand ()
  53. "Insert space and call `dabbrev-expand'."
  54. (interactive)
  55. (execute-kbd-macro (kbd "SPC"))
  56. (call-interactively #'dabbrev-expand))
  57. (defun wi-dabbrev-expand-until-period ()
  58. "Call `wi-dabbrev-expand' until period before cursor."
  59. (interactive)
  60. (unless (string-equal (char-to-string (char-before)) ".")
  61. (wi-dabbrev-expand)
  62. (wi-dabbrev-expand-until-period)))
  63. (defun wi-mark-paragraph+sort-lines ()
  64. "Invoke `mark-paragraph' and `sort-lines'."
  65. (interactive)
  66. (mark-paragraph)
  67. (sort-lines nil (region-beginning) (region-end)))
  68. ;; TODO: Implement wi-define-insert
  69. (defmacro wi-define-insert (name-text-list)
  70. `(mapc (lambda (name-text)
  71. (let ((name (first name-text))
  72. (text (second name-text)))
  73. (defun ,(intern (concat "wi-insert-" (symbol-name name)))
  74. nil
  75. (interactive)
  76. (insert text))))
  77. ,name-text-list))
  78. (defun close-all-parentheses ()
  79. "Close all parentheses."
  80. (interactive "*")
  81. (let ((closing nil))
  82. (save-excursion
  83. (while (condition-case nil
  84. (progn
  85. (backward-up-list)
  86. (let ((syntax (syntax-after (point))))
  87. (case (car syntax)
  88. ((4) (setq closing (cons (cdr syntax) closing)))
  89. ((7 8) (setq closing (cons (char-after (point)) closing)))))
  90. t)
  91. ((scan-error) nil))))
  92. (apply #'insert (nreverse closing))))
  93. (defun wi-copy-buffer (buffer)
  94. "Copy BUFFER to kill ring and save in the GUI’s clipboard."
  95. (with-current-buffer (get-buffer buffer)
  96. (save-excursion
  97. (clipboard-kill-ring-save (point-min) (point-max)))))
  98. (defun wi-copy-current-buffer ()
  99. "Copy current buffer to kill ring and save in the GUI’s clipboard."
  100. (interactive)
  101. (wi-copy-buffer (current-buffer)))
  102. (defun wi-replace-with-brackets-ellipsis ()
  103. "Replace region with \"[…]\"."
  104. (interactive)
  105. (kill-region (region-beginning) (region-end))
  106. (insert "[…]")
  107. (newline 2))
  108. (defun wi-ttn-hs-hide-level-1 ()
  109. (hs-hide-level 1)
  110. (forward-sexp 1))
  111. (setq hs-hide-all-non-comment-function 'wi-ttn-hs-hide-level-1)
  112. ;; Deletes up to the provided character
  113. ;; Doesn’t delete the provided character
  114. ;; Starts the point from before the character rather than after
  115. ;;
  116. ;; Source: https://www.emacswiki.org/emacs/ZapUpToChar
  117. (autoload 'zap-up-to-char "misc"
  118. "Kill up to, but not including ARGth occurrence of CHAR." t)
  119. ;;;
  120. ;;; Anywhere
  121. ;;;
  122. (setq anywhere-kill-buffer nil)
  123. (setq anywhere-major-mode 'text-mode)
  124. (add-hook 'anywhere-mode-hook '(lambda () (activate-input-method "russian-computer")))
  125. (when (functionp #'add-hooks)
  126. (add-hooks '(((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  127. . (lambda ()
  128. (set (make-local-variable 'prettify-symbols-alist)
  129. wi-scheme--prettify-symbols-alist)))
  130. ;; ((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  131. ;; . (lambda () (set-input-method "russian-computer")))
  132. ((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  133. . (lambda () (ispell-change-dictionary "ru")))
  134. ((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  135. . flyspell-mode)
  136. ((anywhere-mode-hook atomic-chrome-edit-mode-hook forge-post-mode-hook)
  137. . abbrev-mode)
  138. ((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  139. . yas-minor-mode)
  140. ((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  141. . (lambda ()
  142. (setq-local company-idle-delay 0.1)
  143. (setq-local company-minimum-prefix-length 2)))
  144. ((anywhere-mode-hook atomic-chrome-edit-mode-hook)
  145. . visual-line-mode))))
  146. (with-eval-after-load 'anywhere-mode
  147. (let ((map anywhere-mode-map))
  148. (define-key map (kbd "C-c '") 'anywhere-exit)
  149. (define-key map (kbd "C-c i") 'ispell-buffer)
  150. (define-key map (kbd "C-c v") 'ivy-yasnippet)))
  151. ;;;
  152. ;;; GhostText
  153. ;;;
  154. (add-hook 'atomic-chrome-edit-mode-hook
  155. #'(lambda ()
  156. (when (or (string= (buffer-name)
  157. "L0ok_At_Me - Chat - Twitch")
  158. (string= (buffer-name)
  159. "sol1st - Chat - Twitch"))
  160. (activate-input-method "russian-computer"))))
  161. ;;;
  162. ;;; Smartparens
  163. ;;;
  164. ;; Structured editing
  165. (with-eval-after-load 'smartparens
  166. (require 'smartparens-config nil t)
  167. (setq sp-highlight-pair-overlay nil)
  168. (sp-use-smartparens-bindings)
  169. ;; Origin <https://github.com/Fuco1/smartparens/blob/master/docs/pair-management.rst>.
  170. (sp-pair "“" "”")
  171. (sp-pair "‘" "’")
  172. (sp-local-pair 'text-mode "<" ">"))
  173. ;;;
  174. ;;; Translate
  175. ;;;
  176. ;; Google translate with translate-shell program
  177. (require 'google-translate-mode nil t)
  178. (with-eval-after-load 'google-translate-mode
  179. (setq trans-target "ru"))
  180. ;;;
  181. ;;; DOS
  182. ;;;
  183. ;; https://stackoverflow.com/questions/730751/hiding-m-in-emacs
  184. (defun remove-dos-eol ()
  185. "Do not show ^M in files containing mixed UNIX and DOS line endings."
  186. (interactive)
  187. (setq buffer-display-table (make-display-table))
  188. (aset buffer-display-table ?\^M []))