1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
;;; ravi-init-insertion.el --- inserting text
;; Copyright (C) 2013
;; Author: <ravi@nero.lan>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Automatic text insertion
;;; Code:
(require 'autoinsert)
(auto-insert-mode)
(use-package yasnippet
:init
(progn
(setq yas-snippet-dirs
`(,(ravi/emacs-file "snippets")
yas-installed-snippets-dir)
)
)
:config
(progn
(yas-global-mode 1)
;; No dropdowns
(setq yas/prompt-functions '(yas/ido-prompt yas/completing-prompt))
;; Wrap around region
(setq yas/wrap-around-region t)
;; Automatically create throw-away snippets
(use-package auto-yasnippet
:bind (("C-<f4>" . aya-create)
("<f4>" . aya-expand))
:ensure t)
)
:diminish yas-minor-mode)
;; Default completion (some day via "M-/")
(require 'hippie-exp)
(setq hippie-expand-try-functions-list
'(yas/hippie-try-expand
try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
)
)
(use-package company
:init
(progn
(add-hook 'after-init-hook 'global-company-mode))
:config
(progn
(setq company-tooltip-flip-when-above t
company-idle-delay 0.1
company-show-numbers t
company-tooltip-align-annotations t
company-require-match nil
company-minimum-prefix-length 2
company-occurrence-weight-function 'company-occurrence-prefer-any-closest
company-dabbrev-downcase nil)
;; Company-mode and company (no pun intended) don't play well with dark themes
(require 'color)
(let ((bg (face-attribute 'default :background)))
(custom-set-faces
`(company-tooltip ((t (:inherit default :background ,(color-lighten-name bg 10)))))
`(company-scrollbar-bg ((t (:background ,(color-lighten-name bg 20)))))
`(company-scrollbar-fg ((t (:background ,(color-lighten-name bg 15)))))
`(company-tooltip-selection ((t (:inherit font-lock-function-name-face))))
`(company-tooltip-common ((t (:inherit font-lock-constant-face))))))
(defun ravi/complete-or-indent ()
(interactive)
(if (company-manual-begin)
(company-complete-common)
(indent-according-to-mode)))
(bind-key "\t" 'ravi/complete-or-indent)
(bind-keys :map company-active-map
("C-n" . company-select-next)
("C-p" . company-select-previous)
;; Swap filter and search since filter is more useful
("C-s" . company-filter-candidates)
("C-M-s" . company-search-candidates))
(bind-keys :map company-search-map
("C-n" . company-select-next)
("C-p" . company-select-previous))
(use-package company-c-headers
:init
(add-to-list 'company-backends 'company-c-headers)
:commands (company-c-headers)
:config
(defun ravi/get-default-include-paths (compiler-executable)
(let* ((gcc-out (shell-command-to-string (concat compiler-executable " -E -x c++ - -v < /dev/null")))
(gcc-list-match (string-match "#include <...> search starts here:\n\\(.*\\(?:\n.*\\)*?\\)End of search list.\n" gcc-out))
(combined-list (match-string 1 gcc-out))
;; Need the following rigamarole to handle paths with spaces in them
(path-list-with-spaces (and combined-list (split-string combined-list "\n" t)))
(path-list (and path-list-with-spaces (mapcar 's-trim-left path-list-with-spaces))))
path-list))
(mapc (lambda (dir) (add-to-list 'company-c-headers-path-system dir)) (ravi/get-default-include-paths "gcc")))
;; To do: enable when moving to emacs 26+
;; (use-package company-box :hook (company-mode-hook . company-box-mode) :ensure t)
(setq ravi/use-company-box nil)
(if ravi/use-company-box
(progn
(use-package all-the-icons)
(use-package company-box
:if window-system
:hook (company-mode-hook . company-box-mode)
:config
(setq company-box-icons-unknown (all-the-icons-faicon "question-circle" :height 0.8))
(setq company-box-icons-elisp
`(,(all-the-icons-faicon "tag" :face font-lock-function-name-face :height 0.8) ;; Function
,(all-the-icons-faicon "cog" :face font-lock-variable-name-face :height 0.8) ;; Variable
,(all-the-icons-faicon "cube" :face font-lock-constant-face :height 0.8) ;; Feature
,(all-the-icons-material "color_lens" :face font-lock-doc-face :height 0.8))) ;; Face
(setq company-box-icons-yasnippet (all-the-icons-faicon "bookmark" :height 0.8))
(setq company-box-icons-lsp
`((1 . ,(all-the-icons-faicon "text-height" :height 0.8)) ;; Text
(2 . ,(all-the-icons-faicon "tags" :face font-lock-function-name-face :height 0.8)) ;; Method
(3 . ,(all-the-icons-faicon "tag" :face font-lock-function-name-face :height 0.8)) ;; Function
(4 . ,(all-the-icons-faicon "tag" :face font-lock-function-name-face :height 0.8)) ;; Constructor
(5 . ,(all-the-icons-faicon "cog" :foreground "#FF9800" :height 0.8)) ;; Field
(6 . ,(all-the-icons-faicon "cog" :foreground "#FF9800" :height 0.8)) ;; Variable
(7 . ,(all-the-icons-faicon "cube" :foreground "#7C4DFF" :height 0.8)) ;; Class
(8 . ,(all-the-icons-faicon "cube" :foreground "#7C4DFF" :height 0.8)) ;; Interface
(9 . ,(all-the-icons-faicon "cube" :foreground "#7C4DFF" :height 0.8)) ;; Module
(10 . ,(all-the-icons-faicon "cog" :foreground "#FF9800" :height 0.8)) ;; Property
(11 . ,(all-the-icons-material "settings_system_daydream" :height 0.8)) ;; Unit
(12 . ,(all-the-icons-faicon "cog" :foreground "#FF9800" :height 0.8)) ;; Value
(13 . ,(all-the-icons-material "storage" :face font-lock-type-face :height 0.8)) ;; Enum
(14 . ,(all-the-icons-material "closed_caption" :foreground "#009688" :height 0.8)) ;; Keyword
(15 . ,(all-the-icons-material "closed_caption" :height 0.8)) ;; Snippet
(16 . ,(all-the-icons-material "color_lens" :face font-lock-doc-face :height 0.8)) ;; Color
(17 . ,(all-the-icons-faicon "file-text-o" :height 0.8)) ;; File
(18 . ,(all-the-icons-material "refresh" :height 0.8)) ;; Reference
(19 . ,(all-the-icons-faicon "folder-open" :height 0.8)) ;; Folder
(20 . ,(all-the-icons-material "closed_caption" :foreground "#009688" :height 0.8)) ;; EnumMember
(21 . ,(all-the-icons-faicon "square" :face font-lock-constant-face :height 0.8)) ;; Constant
(22 . ,(all-the-icons-faicon "cube" :face font-lock-type-face :height 0.8)) ;; Struct
(23 . ,(all-the-icons-faicon "calendar" :height 0.8)) ;; Event
(24 . ,(all-the-icons-faicon "square-o" :height 0.8)) ;; Operator
(25 . ,(all-the-icons-faicon "arrows" :height 0.8))) ;; TypeParameter
)
))
(progn
(use-package company-posframe
:if window-system
:config
(company-posframe-mode 1)
:diminish company-posframe-mode))
)
(unless ravi/use-company-box
(use-package company-quickhelp
:disabled t
:if window-system
:config
(progn
(company-quickhelp-mode 1)
;; Enable company-quickhelp only when company-mode is active
;; (unbind-key "M-h" company-quickhelp-mode-map)
(bind-key "M-h" 'company-quickhelp-manual-begin company-active-map))))
(use-package company-statistics
:init
(setq company-statistics-file (expand-file-name "company-statistics-cache.el"
(ravi/emacs-file "past")))
:config
(progn
(company-statistics-mode)))
;; Get rid of company-semantic as it interferes with clang-based backends
(setq company-backends (delete 'company-semantic company-backends))
;; Get rid of company-clang since it is too noisy at this point
(setq company-backends (delete 'company-clang company-backends))
(require 'company-yasnippet)
(defun ravi/company-to-yasnippet ()
(interactive)
(company-abort)
(call-interactively 'company-yasnippet))
(bind-key "<backtab>" 'ravi/company-to-yasnippet company-active-map)
(bind-key "<backtab>" 'company-yasnippet))
:diminish company-mode)
(use-package copy-as-format
:commands (copy-as-format))
(provide 'ravi-init-insertion)
;;; ravi-init-insertion.el ends here
|