PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/emacs.cat/org-config.backup.cat/csb-completions.org

https://gitlab.com/csantosb/wikidata
Org | 287 lines | 231 code | 56 blank | 0 comment | 6 complexity | 3c88c9ecdf478eeb5f6df8b1a3b60193 MD5 | raw file
  1. ---
  2. format: Org
  3. categories: emacs config completions
  4. toc: yes
  5. title: csb-completions
  6. content: emacs completions config file
  7. ...
  8. * Table of Contents :TOC:noexport:
  9. :PROPERTIES:
  10. :VISIBILITY: all
  11. :END:
  12. - [[#introduction][Introduction]]
  13. - [[#header][Header]]
  14. - [[#company-mode][Company-mode]]
  15. - [[#company][Company]]
  16. - [[#keys][Keys]]
  17. - [[#variables][Variables]]
  18. - [[#use][Use]]
  19. - [[#yasnippet][Yasnippet]]
  20. - [[#keys-1][Keys]]
  21. - [[#helm-yasnippet][helm-yasnippet]]
  22. - [[#abbrev-mode][Abbrev mode]]
  23. - [[#references][References]]
  24. - [[#dabbrev-mode][Dabbrev mode]]
  25. - [[#helm-dabbrev][helm-dabbrev]]
  26. - [[#references-1][References]]
  27. - [[#auto-complete][Auto complete]]
  28. - [[#trailer][Trailer]]
  29. * Introduction
  30. ;; Use space and punctuation to acce the current the most likely completion.
  31. ;; (setq auto-completion-syntax-alist (quote ( accept . word)))
  32. ;; Avoid completion for short trivial words.
  33. ;; (setq-local auto-completion-min-chars (quote ( . 3)))
  34. * Header
  35. #+begin_src emacs-lisp
  36. ;; package --- Summary
  37. ;;
  38. ;;; Commentary:
  39. ;;
  40. ;; This file contains ...
  41. ;;
  42. ;;; Code:
  43. #+end_src
  44. - helm-lisp-completion-at-point
  45. * Company-mode
  46. ** Configuration
  47. #+begin_src emacs-lisp
  48. (use-package company
  49. :defer t
  50. :init (global-company-mode t)
  51. :bind
  52. (:map launcher-map
  53. ("SPC" . company-complete))
  54. ;; When company menu is active, these keys are made available
  55. (:map company-active-map
  56. ("TAB" . company-complete-common)
  57. ("C-j" . company-complete-selection)
  58. ("<f1>" . company-show-doc-buffer)
  59. ("C-h" . company-show-doc-buffer)
  60. ("C-g" . company-abort)
  61. ("M-n" . nil)
  62. ("M-p" . nil)
  63. ("C-n" . company-select-next)
  64. ("C-p" . company-select-previous)
  65. ("C-w" . company-show-location)
  66. ("C-s" . company-search-candidates)
  67. ("C-M-s" . company-filter-candidates))
  68. :config
  69. ;; Company Flx adds fuzzy matching to company, powered by the sophisticated
  70. ;; sorting heuristics in =flx=
  71. ;; (use-package company-flx
  72. ;; :after company
  73. ;; ;; global minor mode
  74. ;; :init (company-flx-mode t))
  75. ;; Company fuzzy
  76. ;; (use-package company-fuzzy
  77. ;; :after company
  78. ;; )
  79. ;; (require 'company-fuzzy)
  80. ;; (global-company-fuzzy-mode t)
  81. (company-emoji-init)
  82. ;; Company posframe
  83. ;; (company-posframe-mode 1)
  84. ;; Company quickhelp
  85. (company-quickhelp-mode t)
  86. (setq company-quickhelp-delay 0.2
  87. company-quickhelp-max-lines nil)
  88. ;; With use-package:
  89. ;; (use-package company-box
  90. ;; :after company
  91. ;; :hook (prog-mode . company-box-mode))
  92. ;; Company-gtags: gtags backend for company.
  93. ;; (require 'company-gtags)
  94. ;; Modes that use company-gtags, complete if necessary
  95. ;; (add-to-list (make-local-variable 'company-gtags-modes)
  96. ;; 'vhdl-mode)
  97. ;; (add-hook 'company-mode-hook
  98. ;; (lambda ()
  99. ;; ;; Use it only when a proper gtags setup is present
  100. ;; (when
  101. ;; (and (buffer-file-name)
  102. ;; (vc-find-root (buffer-file-name) ".git")
  103. ;; (file-exists-p
  104. ;; (format "%sGTAGS" (vc-root-dir))))
  105. ;; (add-to-list (make-local-variable 'company-backends)
  106. ;; 'company-gtags))))
  107. ;; ;; Variables
  108. (setq company-dabbrev-ignore-case nil
  109. company-dabbrev-code-ignore-case nil
  110. ;; Based on [[https://tsdh.wordpress.com/2013/08/27/adjusting-company-mode-to-not-change-buffer-contents-accidentally/][Adjusting company-mode to not change buffer contents accidentally]].
  111. ;; company-begin-commands '(self-insert-command org-self-insert-command)
  112. company-dabbrev-downcase nil
  113. company-idle-delay 0.01
  114. company-echo-delay 0.01
  115. company-tooltip-limit 10
  116. ;; company-format-margin-function #'company-vscode-light-icons-margin
  117. company-format-margin-function #'company-detect-icons-margin
  118. company-minimum-prefix-length 1))
  119. #+end_src
  120. and then call it with =company-complete= to initiate completion manually; this is
  121. not necessary, should activate by itself.
  122. ** Keys
  123. I use =company-yasnippet= in addition to the following.
  124. ** Use
  125. Example of use
  126. #+begin_src emacs-lisp :tangle no
  127. (setq company-backends
  128. '((company-files ; files & directory
  129. company-keywords ; keywords
  130. company-capf
  131. company-yasnippet)
  132. (company-abbrev company-dabbrev)))
  133. (add-hook 'python-mode-hook
  134. (lambda ()
  135. (add-to-list (make-local-variable 'company-backends)
  136. 'company-anaconda)))
  137. (dolist (hook '(js-mode-hook
  138. js2-mode-hook
  139. js3-mode-hook
  140. inferior-js-mode-hook ))
  141. (add-hook hook
  142. (lambda ()
  143. (tern-mode t)
  144. (add-to-list (make-local-variable 'company-backends)
  145. 'company-tern))))
  146. #+end_src
  147. * Yasnippet
  148. Then I add the company backend to company, so that all completions go through it.
  149. Finally, I unbound yas-expand from TAB, used by company.
  150. yas-expand
  151. _References_
  152. - [[http://kitchingroup.cheme.cmu.edu/blog/2014/02/17/yasnippets-for-jasp-ase-and-python/][Example use]]
  153. - Advanced example of use : [[http://kitchingroup.cheme.cmu.edu/blog/2014/02/16/A-dynamic-snippet-for-a-task-due-7-days-from-now/][A dynamic snippet for a task due 7 days from now]]
  154. - [[http://howardism.org/Technical/Emacs/templates-tutorial.html]]
  155. - http://www.howardism.org/Technical/Emacs/templates-tutorial.html
  156. - [[elfeed:planet.emacsen.org#http://irreal.org/blog/?p=6313][Irreal: Choice Lists for Yasnippets]]
  157. #+begin_src emacs-lisp
  158. (use-package yasnippet
  159. :init (yas-global-mode 1))
  160. #+end_src
  161. ** Keys
  162. I use =helm-yas-complete= bound to =C-x c y= to select snippets.
  163. #+begin_src emacs-lisp :tangle no
  164. ;; (add-to-list 'company-backends 'company-yasnippet)
  165. (with-eval-after-load 'yasnippet
  166. ;; (define-key yas-keymap [(tab)] 'yas-next-field-or-maybe-expand)
  167. ;; (define-key yas-keymap (kbd "TAB") 'yas-next-field-or-maybe-expand)
  168. ;; (define-key yas-keymap [(shift tab)] 'yas-prev-field)
  169. ;; (define-key yas-keymap [backtab] 'yas-prev-field)
  170. ;; (define-key yas-keymap (kbd "C-g") 'yas-abort-snippet)
  171. ;; (define-key yas-keymap (kbd "C-d") 'yas-skip-and-clear-or-delete-char)
  172. (define-key yas-minor-mode-map [(tab)] nil) ;; 'yas-expand
  173. (define-key yas-minor-mode-map (kbd "TAB") 'yas-expand) ;; 'yas-expand
  174. ;; maybe C-c y ?? to expand
  175. (define-key yas-minor-mode-map (kbd "C-c yy") 'company-yasnippet)
  176. (define-key yas-minor-mode-map (kbd "C-c yn") 'yas-new-snippet)
  177. (define-key yas-minor-mode-map (kbd "C-c ye") 'yas-expand)
  178. (define-key yas-minor-mode-map (kbd "C-c yi") 'yas-insert-snippet)
  179. (define-key yas-minor-mode-map (kbd "C-c yv") 'yas-visit-snippet-file))
  180. #+end_src
  181. *** helm-yasnippet
  182. [[file:csb-helm.page::*Helm%20yasnippet][Helm yasnippet]] in helm page.
  183. * Abbrev mode
  184. #+begin_src emacs-lisp
  185. (use-package abbrev
  186. :init (abbrev-mode 1)
  187. :ensure nil
  188. :config
  189. (setq-default abbrev-mode t)
  190. (setq save-abbrevs 'silently)
  191. (setq abbrev-file-name (concat user-emacs-directory ".abbrev_defs"))
  192. (if (file-exists-p abbrev-file-name)
  193. (quietly-read-abbrev-file)))
  194. ;; (add-hook 'after-init-hook 'abbrev-mode)
  195. ;; (with-eval-after-load 'abbrev
  196. ;; (add-to-list (make-local-variable 'company-backends)
  197. ;; 'company-abbrev))
  198. #+end_src
  199. _References_
  200. - http://www.wisdomandwonder.com/link/9385/expanding-and-using-abbreviations-in-emacs
  201. - https://groups.google.com/forum/#!topic/gnu.emacs.help/kHvUcFdiXFM
  202. * Dabbrev mode
  203. #+begin_src emacs-lisp :tangle no
  204. ;; I am not using helm's dabbrev 'C-x c c', as I prefer to add the backend to company
  205. (global-unset-key (kbd "M-/")) ;; dabrev-expand
  206. (global-unset-key (kbd "C-M-/")) ;; dabrev-complete
  207. ;; (with-eval-after-load 'abbrev (add-to-list 'company-backends 'company-dabbrev-code)) ;; auto done
  208. ;; (add-to-list 'company-backends 'company-dabbrev)
  209. #+end_src
  210. _References_
  211. - http://oremacs.com/2014/12/28/trying-abbrevs/
  212. - http://pastebin.com/D7Lrg3WA
  213. - https://github.com/andreas-roehler/werkstatt/blob/master/teens-abbrevs.el
  214. *** helm-dabbrev
  215. [[file:csb-helm.page::*Helm%20yasnippet][Helm dabbrev]] in helm page.
  216. * Auto complete
  217. ;; (ac-config-default)
  218. ;; (global-auto-complete-mode t)
  219. ;; (add-to-list 'ac-dictionary-directories "")
  220. ;; (setq-default auto-completion-min-chars (quote ( . 3)))
  221. ;; (setq auto-completion-syntax-alist (quote (global accept . word))) ;; Use space and punctuation to acce the current the most likely completion.
  222. ;; (setq-default auto-completion-min-chars (quote (global . 3))) ;; Avoid completion for short trivial words.
  223. ;; Auto Complete Auctex __________________________________________________________________________
  224. ;; (add-to-list 'load-path "~/Dropbox/.emacs.d/auto-complete-auctex")
  225. ;; (require 'auto-complete-auctex)
  226. * Trailer
  227. #+begin_src emacs-lisp
  228. (provide 'csb-completions)
  229. (message (format "Loaded csb-completions !"))
  230. ;;; csb-completions.el ends here
  231. #+end_src