/emacs.cat/org-config.backup.cat/csb-completions.org
Org | 287 lines | 231 code | 56 blank | 0 comment | 6 complexity | 3c88c9ecdf478eeb5f6df8b1a3b60193 MD5 | raw file
- ---
- format: Org
- categories: emacs config completions
- toc: yes
- title: csb-completions
- content: emacs completions config file
- ...
- * Table of Contents :TOC:noexport:
- :PROPERTIES:
- :VISIBILITY: all
- :END:
- - [[#introduction][Introduction]]
- - [[#header][Header]]
- - [[#company-mode][Company-mode]]
- - [[#company][Company]]
- - [[#keys][Keys]]
- - [[#variables][Variables]]
- - [[#use][Use]]
- - [[#yasnippet][Yasnippet]]
- - [[#keys-1][Keys]]
- - [[#helm-yasnippet][helm-yasnippet]]
- - [[#abbrev-mode][Abbrev mode]]
- - [[#references][References]]
- - [[#dabbrev-mode][Dabbrev mode]]
- - [[#helm-dabbrev][helm-dabbrev]]
- - [[#references-1][References]]
- - [[#auto-complete][Auto complete]]
- - [[#trailer][Trailer]]
- * Introduction
- ;; Use space and punctuation to acce the current the most likely completion.
- ;; (setq auto-completion-syntax-alist (quote ( accept . word)))
- ;; Avoid completion for short trivial words.
- ;; (setq-local auto-completion-min-chars (quote ( . 3)))
- * Header
- #+begin_src emacs-lisp
- ;; package --- Summary
- ;;
- ;;; Commentary:
- ;;
- ;; This file contains ...
- ;;
- ;;; Code:
- #+end_src
- - helm-lisp-completion-at-point
- * Company-mode
- ** Configuration
- #+begin_src emacs-lisp
- (use-package company
- :defer t
- :init (global-company-mode t)
- :bind
- (:map launcher-map
- ("SPC" . company-complete))
- ;; When company menu is active, these keys are made available
- (:map company-active-map
- ("TAB" . company-complete-common)
- ("C-j" . company-complete-selection)
- ("<f1>" . company-show-doc-buffer)
- ("C-h" . company-show-doc-buffer)
- ("C-g" . company-abort)
- ("M-n" . nil)
- ("M-p" . nil)
- ("C-n" . company-select-next)
- ("C-p" . company-select-previous)
- ("C-w" . company-show-location)
- ("C-s" . company-search-candidates)
- ("C-M-s" . company-filter-candidates))
- :config
- ;; Company Flx adds fuzzy matching to company, powered by the sophisticated
- ;; sorting heuristics in =flx=
- ;; (use-package company-flx
- ;; :after company
- ;; ;; global minor mode
- ;; :init (company-flx-mode t))
- ;; Company fuzzy
- ;; (use-package company-fuzzy
- ;; :after company
- ;; )
- ;; (require 'company-fuzzy)
- ;; (global-company-fuzzy-mode t)
- (company-emoji-init)
- ;; Company posframe
- ;; (company-posframe-mode 1)
- ;; Company quickhelp
- (company-quickhelp-mode t)
- (setq company-quickhelp-delay 0.2
- company-quickhelp-max-lines nil)
- ;; With use-package:
- ;; (use-package company-box
- ;; :after company
- ;; :hook (prog-mode . company-box-mode))
- ;; Company-gtags: gtags backend for company.
- ;; (require 'company-gtags)
- ;; Modes that use ‘company-gtags’, complete if necessary
- ;; (add-to-list (make-local-variable 'company-gtags-modes)
- ;; 'vhdl-mode)
- ;; (add-hook 'company-mode-hook
- ;; (lambda ()
- ;; ;; Use it only when a proper gtags setup is present
- ;; (when
- ;; (and (buffer-file-name)
- ;; (vc-find-root (buffer-file-name) ".git")
- ;; (file-exists-p
- ;; (format "%sGTAGS" (vc-root-dir))))
- ;; (add-to-list (make-local-variable 'company-backends)
- ;; 'company-gtags))))
- ;; ;; Variables
- (setq company-dabbrev-ignore-case nil
- company-dabbrev-code-ignore-case nil
- ;; 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]].
- ;; company-begin-commands '(self-insert-command org-self-insert-command)
- company-dabbrev-downcase nil
- company-idle-delay 0.01
- company-echo-delay 0.01
- company-tooltip-limit 10
- ;; company-format-margin-function #'company-vscode-light-icons-margin
- company-format-margin-function #'company-detect-icons-margin
- company-minimum-prefix-length 1))
- #+end_src
- and then call it with =company-complete= to initiate completion manually; this is
- not necessary, should activate by itself.
- ** Keys
- I use =company-yasnippet= in addition to the following.
- ** Use
- Example of use
- #+begin_src emacs-lisp :tangle no
- (setq company-backends
- '((company-files ; files & directory
- company-keywords ; keywords
- company-capf
- company-yasnippet)
- (company-abbrev company-dabbrev)))
- (add-hook 'python-mode-hook
- (lambda ()
- (add-to-list (make-local-variable 'company-backends)
- 'company-anaconda)))
- (dolist (hook '(js-mode-hook
- js2-mode-hook
- js3-mode-hook
- inferior-js-mode-hook ))
- (add-hook hook
- (lambda ()
- (tern-mode t)
- (add-to-list (make-local-variable 'company-backends)
- 'company-tern))))
- #+end_src
- * Yasnippet
- Then I add the company backend to company, so that all completions go through it.
- Finally, I unbound yas-expand from TAB, used by company.
- yas-expand
- _References_
- - [[http://kitchingroup.cheme.cmu.edu/blog/2014/02/17/yasnippets-for-jasp-ase-and-python/][Example use]]
- - 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]]
- - [[http://howardism.org/Technical/Emacs/templates-tutorial.html]]
- - http://www.howardism.org/Technical/Emacs/templates-tutorial.html
- - [[elfeed:planet.emacsen.org#http://irreal.org/blog/?p=6313][Irreal: Choice Lists for Yasnippets]]
- #+begin_src emacs-lisp
- (use-package yasnippet
- :init (yas-global-mode 1))
- #+end_src
- ** Keys
- I use =helm-yas-complete= bound to =C-x c y= to select snippets.
- #+begin_src emacs-lisp :tangle no
- ;; (add-to-list 'company-backends 'company-yasnippet)
- (with-eval-after-load 'yasnippet
- ;; (define-key yas-keymap [(tab)] 'yas-next-field-or-maybe-expand)
- ;; (define-key yas-keymap (kbd "TAB") 'yas-next-field-or-maybe-expand)
- ;; (define-key yas-keymap [(shift tab)] 'yas-prev-field)
- ;; (define-key yas-keymap [backtab] 'yas-prev-field)
- ;; (define-key yas-keymap (kbd "C-g") 'yas-abort-snippet)
- ;; (define-key yas-keymap (kbd "C-d") 'yas-skip-and-clear-or-delete-char)
- (define-key yas-minor-mode-map [(tab)] nil) ;; 'yas-expand
- (define-key yas-minor-mode-map (kbd "TAB") 'yas-expand) ;; 'yas-expand
- ;; maybe C-c y ?? to expand
- (define-key yas-minor-mode-map (kbd "C-c yy") 'company-yasnippet)
- (define-key yas-minor-mode-map (kbd "C-c yn") 'yas-new-snippet)
- (define-key yas-minor-mode-map (kbd "C-c ye") 'yas-expand)
- (define-key yas-minor-mode-map (kbd "C-c yi") 'yas-insert-snippet)
- (define-key yas-minor-mode-map (kbd "C-c yv") 'yas-visit-snippet-file))
- #+end_src
- *** helm-yasnippet
- [[file:csb-helm.page::*Helm%20yasnippet][Helm yasnippet]] in helm page.
- * Abbrev mode
- #+begin_src emacs-lisp
- (use-package abbrev
- :init (abbrev-mode 1)
- :ensure nil
- :config
- (setq-default abbrev-mode t)
- (setq save-abbrevs 'silently)
- (setq abbrev-file-name (concat user-emacs-directory ".abbrev_defs"))
- (if (file-exists-p abbrev-file-name)
- (quietly-read-abbrev-file)))
- ;; (add-hook 'after-init-hook 'abbrev-mode)
- ;; (with-eval-after-load 'abbrev
- ;; (add-to-list (make-local-variable 'company-backends)
- ;; 'company-abbrev))
- #+end_src
- _References_
- - http://www.wisdomandwonder.com/link/9385/expanding-and-using-abbreviations-in-emacs
- - https://groups.google.com/forum/#!topic/gnu.emacs.help/kHvUcFdiXFM
- * Dabbrev mode
- #+begin_src emacs-lisp :tangle no
- ;; I am not using helm's dabbrev 'C-x c c', as I prefer to add the backend to company
- (global-unset-key (kbd "M-/")) ;; dabrev-expand
- (global-unset-key (kbd "C-M-/")) ;; dabrev-complete
- ;; (with-eval-after-load 'abbrev (add-to-list 'company-backends 'company-dabbrev-code)) ;; auto done
- ;; (add-to-list 'company-backends 'company-dabbrev)
- #+end_src
- _References_
- - http://oremacs.com/2014/12/28/trying-abbrevs/
- - http://pastebin.com/D7Lrg3WA
- - https://github.com/andreas-roehler/werkstatt/blob/master/teens-abbrevs.el
- *** helm-dabbrev
- [[file:csb-helm.page::*Helm%20yasnippet][Helm dabbrev]] in helm page.
- * Auto complete
- ;; (ac-config-default)
- ;; (global-auto-complete-mode t)
- ;; (add-to-list 'ac-dictionary-directories "")
- ;; (setq-default auto-completion-min-chars (quote ( . 3)))
- ;; (setq auto-completion-syntax-alist (quote (global accept . word))) ;; Use space and punctuation to acce the current the most likely completion.
- ;; (setq-default auto-completion-min-chars (quote (global . 3))) ;; Avoid completion for short trivial words.
- ;; Auto Complete Auctex __________________________________________________________________________
- ;; (add-to-list 'load-path "~/Dropbox/.emacs.d/auto-complete-auctex")
- ;; (require 'auto-complete-auctex)
- * Trailer
- #+begin_src emacs-lisp
- (provide 'csb-completions)
- (message (format "Loaded csb-completions !"))
- ;;; csb-completions.el ends here
- #+end_src