feat(emacs/README.md): add elisp which installs required packages
This commit is contained in:
parent
83f05e104a
commit
0426d04cb9
2 changed files with 101 additions and 7 deletions
|
@ -11,10 +11,11 @@ Requirement
|
|||
``lean-mode`` requires [Emacs 24][emacs24] and following (optional)
|
||||
packages which can be installed via <kbd>M-x package-install</kbd>.
|
||||
|
||||
- [company][company]
|
||||
- [dash][dash]
|
||||
- [dash-functional][dash]
|
||||
- [flycheck][flycheck]
|
||||
- [fill-column-indicator][fci]
|
||||
- [flycheck][flycheck]
|
||||
- [whitespace-cleanup-mode][wcm]
|
||||
|
||||
To install them, you need to have [MELPA][MELPA] in your
|
||||
|
@ -32,13 +33,26 @@ code:
|
|||
[wcm]: https://github.com/purcell/whitespace-cleanup-mode
|
||||
[MELPA]: http://melpa.milkbox.net
|
||||
[dash]: https://github.com/magnars/dash.el
|
||||
|
||||
Setup
|
||||
[company]: http://company-mode.github.io/
|
||||
-----
|
||||
|
||||
Put the following elisp code on your emacs setup:
|
||||
|
||||
```elisp
|
||||
(require 'package)
|
||||
(add-to-list 'package-archives
|
||||
'("melpa" . "http://melpa.milkbox.net/packages/") t)
|
||||
(package-initialize)
|
||||
(when (not package-archive-contents) (package-refresh-contents))
|
||||
|
||||
;; Install required packages for lean-mode
|
||||
(defvar lean-mode-required-packages
|
||||
'(company dash dash-functional flycheck whitespace-cleanup-mode fill-column-indicator))
|
||||
(dolist (p lean-mode-required-packages)
|
||||
(when (not (package-installed-p p))
|
||||
(package-install p)))
|
||||
|
||||
;; Set up lean-root path
|
||||
(setq lean-rootdir "~/projects/lean")
|
||||
(setq-local lean-emacs-path
|
||||
(concat (file-name-as-directory lean-rootdir)
|
||||
|
@ -47,11 +61,10 @@ Put the following elisp code on your emacs setup:
|
|||
(add-to-list 'load-path (expand-file-name lean-emacs-path))
|
||||
(require 'lean-mode)
|
||||
|
||||
;; lean customization
|
||||
(customize-set-variable 'lean-show-rule-column-method 'vline)
|
||||
(customize-set-variable 'lean-rule-column 100)
|
||||
(customize-set-variable 'lean-rule-color "#ff0000")
|
||||
;; Customization for lean-mode
|
||||
(customize-set-variable 'lean-delete-trailing-whitespace t)
|
||||
(customize-set-variable 'lean-flycheck-use t)
|
||||
(customize-set-variable 'lean-eldoc-use t)
|
||||
```
|
||||
|
||||
Key Bindings
|
||||
|
|
81
src/emacs/lean-company.el
Normal file
81
src/emacs/lean-company.el
Normal file
|
@ -0,0 +1,81 @@
|
|||
(require 'company)
|
||||
(defun company-lean ()
|
||||
(set (make-local-variable 'company-backends) '(company-lean))
|
||||
(company-mode))
|
||||
(add-hook 'lean-mode-hook 'company-lean)
|
||||
|
||||
(setq company-tooltip-limit 20) ; bigger popup window
|
||||
(setq company-idle-delay .3) ; decrease delay before autocompletion popup shows
|
||||
(setq company-echo-delay 0) ; remove annoying blinking
|
||||
(setq company-begin-commands '(self-insert-command)) ; start autocompletion only after typing
|
||||
|
||||
(defun company-lean--prefix ()
|
||||
"Returns the symbol to complete. Also, if point is on a dot,
|
||||
triggers a completion immediately."
|
||||
(if company-lean-begin-after-member-access
|
||||
(company-grab-symbol-cons "\\." 1)
|
||||
(company-grab-symbol)))
|
||||
|
||||
(defun company-go--invoke-autocomplete ()
|
||||
(let ((temp-buffer (generate-new-buffer "*leancompany*")))
|
||||
(prog2
|
||||
(call-process-region (point-min)
|
||||
(point-max)
|
||||
"leancompany"
|
||||
nil
|
||||
temp-buffer
|
||||
nil
|
||||
"-f=csv"
|
||||
"autocomplete"
|
||||
(or (buffer-file-name) "")
|
||||
(concat "c" (int-to-string (- (point) 1))))
|
||||
(with-current-buffer temp-buffer (buffer-string))
|
||||
(kill-buffer temp-buffer))))
|
||||
|
||||
(defun company-lean--candidates ()
|
||||
(company-lean--get-candidates (split-string (company-lean--invoke-autocomplete) "\n" t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun company-lean (command &optional arg &rest ignored)
|
||||
(case command
|
||||
(prefix (and (derived-mode-p 'lean-mode)
|
||||
(not (company-in-string-or-comment))
|
||||
(or (company-lean--prefix) 'stop)))
|
||||
(candidates (company-lean--candidates))
|
||||
(meta (get-text-property 0 'meta arg))
|
||||
(annotation
|
||||
(when company-lean-show-annotation
|
||||
(get-text-property 0 'meta arg)))
|
||||
(location (company-lean--location arg))
|
||||
(sorted t)))
|
||||
|
||||
(provide 'company-lean)
|
||||
|
||||
(defun company-lean--doc-buffer (candidate)
|
||||
(message "doc candidate = %S" candidate)
|
||||
(company-doc-buffer (get-text-property 0 'doc candidate)))
|
||||
|
||||
(defun company-lean--annotation (candidate)
|
||||
(message "annotation candidate = %S" candidate)
|
||||
(let ((anno (get-text-property 0 'kind candidate)))
|
||||
(when anno (concat " blabla" anno)))
|
||||
" : annotation1")
|
||||
|
||||
(defun company-lean--candidates (prefix)
|
||||
(cl-loop for x in '("foobar" "foobaz" "foobarbaz")
|
||||
collect x
|
||||
))
|
||||
|
||||
(defun company-my-backend (command &optional arg &rest ignored)
|
||||
(interactive (list 'interactive))
|
||||
(case command
|
||||
(interactive (company-begin-backend 'company-my-backend))
|
||||
(prefix (when (looking-back "foo\\>")
|
||||
(match-string 0)))
|
||||
(candidates (company-lean--candidates arg))
|
||||
(annotation (company-lean--annotation arg))
|
||||
))
|
||||
|
||||
(set (make-local-variable 'company-backends) '(company-my-backend))
|
||||
(company-mode)
|
||||
|
Loading…
Reference in a new issue