PageRenderTime 59ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/init-helm-aborn.el

https://github.com/aborn/emacs.d
Emacs Lisp | 376 lines | 221 code | 53 blank | 102 comment | 2 complexity | 0fea0d6bc9afa35e65d1eb2e0acc0c7f MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. ;; --------------------------------------------------------------------
  2. ;; init-helm-thierry.el --- My startup file for helm. -*- lexical-binding: t -*-
  3. ;; fork 于https://github.com/thierryvolpiatto/emacs-tv-config/blob/master/init-helm-thierry.el
  4. ;; helm https://github.com/emacs-helm/helm
  5. ;; install first:
  6. ;; git clone https://github.com/emacs-helm/helm.git ~/.emacs.d/site-lisp
  7. ;; git clone https://github.com/jwiegley/emacs-async.git ~/.emacs.d/site-lisp
  8. ;; --------------------------------------------------------------------
  9. (require 'helm-config)
  10. (require 'helm-ls-git)
  11. ;; Enable Modes (This is loading nearly everything).
  12. (helm-mode 1)
  13. ;; (helm-adaptative-mode 1)
  14. (helm-autoresize-mode 1)
  15. (helm-push-mark-mode 1)
  16. ;;;; Extensions
  17. ;;
  18. ;;(load "/home/thierry/elisp/helm-extensions/helm-extensions-autoloads.el")
  19. ;;;; Test Sources or new helm code.
  20. ;; !!!WARNING EXPERIMENTAL!!!
  21. (defun helm-version ()
  22. (with-temp-buffer
  23. (insert-file-contents (find-library-name "helm-pkg"))
  24. (goto-char (point-min))
  25. (when (re-search-forward
  26. "\\([0-9]+?\\)\\.\\([0-9]+?\\)\\.\\([0-9]+?\\)\\.?[0-9]*" nil t)
  27. (match-string-no-properties 0))))
  28. (defun helm-git-version ()
  29. (shell-command-to-string
  30. "git log --pretty='format:%H' -1"))
  31. (unless (fboundp 'helm-hide-minibuffer-maybe)
  32. (defun helm-hide-minibuffer-maybe ()
  33. (when (with-helm-buffer helm-echo-input-in-header-line)
  34. (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
  35. (overlay-put ov 'window (selected-window))
  36. (overlay-put ov 'face (let ((bg-color (face-background 'default nil)))
  37. `(:background ,bg-color :foreground ,bg-color)))
  38. (setq-local cursor-type nil)))))
  39. (defun helm/turn-on-header-line ()
  40. (interactive)
  41. (setq helm-echo-input-in-header-line t)
  42. (helm-autoresize-mode -1)
  43. (add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
  44. )
  45. (defun helm/turn-off-header-line ()
  46. (interactive)
  47. (setq helm-echo-input-in-header-line nil)
  48. (helm-autoresize-mode 1)
  49. (remove-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
  50. )
  51. ;;; Helm-command-map
  52. (define-key helm-command-map (kbd "g") 'helm-apt)
  53. (define-key helm-command-map (kbd "w") 'helm-psession)
  54. (define-key helm-command-map (kbd "z") 'helm-complex-command-history)
  55. (define-key helm-command-map (kbd "w") 'helm-w3m-bookmarks)
  56. (define-key helm-command-map (kbd "x") 'helm-firefox-bookmarks)
  57. (define-key helm-command-map (kbd "#") 'helm-emms)
  58. (define-key helm-command-map (kbd "I") 'helm-imenu-in-all-buffers)
  59. ;;; Global-map
  60. (global-set-key (kbd "M-x") 'undefined)
  61. (global-set-key (kbd "M-x") 'helm-M-x)
  62. (global-set-key (kbd "M-y") 'helm-show-kill-ring)
  63. (global-set-key (kbd "C-c f") 'helm-recentf)
  64. (global-set-key (kbd "C-x C-f") 'helm-find-files)
  65. (global-set-key (kbd "C-c <SPC>") 'helm-all-mark-rings)
  66. (global-set-key (kbd "C-x r b") 'helm-filtered-bookmarks)
  67. (global-set-key (kbd "C-h r") 'helm-info-emacs)
  68. ;;(global-set-key (kbd "C-:") 'helm-eval-expression-with-eldoc)
  69. (global-set-key (kbd "C-,") 'helm-calcul-expression)
  70. (global-set-key (kbd "C-h i") 'helm-info-at-point)
  71. (global-set-key (kbd "C-x C-d") 'helm-browse-project)
  72. (global-set-key (kbd "<f1>") 'helm-resume)
  73. (global-set-key (kbd "C-h C-f") 'helm-apropos)
  74. (global-set-key (kbd "<f5> s") 'helm-find)
  75. (global-set-key (kbd "<f2>") 'helm-execute-kmacro)
  76. ;;(global-set-key (kbd "C-c g") 'helm-gid)
  77. (global-set-key (kbd "C-c g") 'helm-ls-git-ls)
  78. (global-set-key (kbd "C-c i") 'helm-imenu-in-all-buffers)
  79. (define-key global-map [remap jump-to-register] 'helm-register)
  80. (define-key global-map [remap list-buffers] 'helm-buffers-list)
  81. (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
  82. (define-key global-map [remap find-tag] 'helm-etags-select)
  83. (define-key global-map [remap xref-find-definitions] 'helm-etags-select)
  84. (define-key shell-mode-map (kbd "M-p") 'helm-comint-input-ring) ; shell history.
  85. ;;; Lisp complete or indent. (Rebind <tab>)
  86. ;;
  87. ;; Use `completion-at-point' with `helm-mode' if available
  88. ;; otherwise fallback to helm implementation.
  89. ;; Set to `complete' will use `completion-at-point'.
  90. ;; (and (boundp 'tab-always-indent)
  91. ;; (setq tab-always-indent 'complete))
  92. (helm-multi-key-defun helm-multi-lisp-complete-at-point
  93. "Multi key function for completion in emacs lisp buffers.
  94. First call indent, second complete symbol, third complete fname."
  95. '(helm-lisp-indent
  96. helm-lisp-completion-at-point
  97. helm-complete-file-name-at-point)
  98. 0.3)
  99. (if (and (boundp 'tab-always-indent)
  100. (eq tab-always-indent 'complete)
  101. (boundp 'completion-in-region-function))
  102. (progn
  103. (define-key lisp-interaction-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  104. (define-key emacs-lisp-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  105. ;; lisp complete. (Rebind M-<tab>)
  106. (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
  107. (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
  108. (define-key lisp-interaction-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  109. (define-key emacs-lisp-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  110. ;; lisp complete. (Rebind M-<tab>)
  111. (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
  112. (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
  113. (unless (boundp 'completion-in-region-function)
  114. (add-hook 'ielm-mode-hook
  115. #'(lambda ()
  116. (define-key ielm-map [remap completion-at-point] 'helm-lisp-completion-at-point))))
  117. ;;; helm completion in minibuffer
  118. ;;
  119. ;; (define-key minibuffer-local-map [remap completion-at-point] 'helm-lisp-completion-at-point) ; >24.3
  120. ;; (define-key minibuffer-local-map [remap lisp-complete-symbol] 'helm-lisp-completion-at-point) ; <=24.3
  121. ;;; helm find files
  122. (define-key helm-find-files-map (kbd "C-d") 'helm-ff-persistent-delete)
  123. (define-key helm-buffer-map (kbd "C-d") 'helm-buffer-run-kill-persistent)
  124. ;; Use default-as-input in grep
  125. (add-to-list 'helm-sources-using-default-as-input 'helm-source-grep)
  126. ;;; Describe key-bindings
  127. ;;
  128. ;;
  129. ;; (helm-descbinds-install) ; C-h b, C-x C-h
  130. ;;; Helm-variables
  131. (setq helm-google-suggest-use-curl-p t
  132. ;helm-kill-ring-threshold 1
  133. helm-raise-command "wmctrl -xa %s"
  134. helm-scroll-amount 4
  135. ;helm-quick-update t
  136. helm-idle-delay 0.01
  137. helm-input-idle-delay 0.01
  138. ;helm-completion-window-scroll-margin 0
  139. ;helm-display-source-at-screen-top nil
  140. helm-ff-search-library-in-sexp t
  141. ;helm-kill-ring-max-lines-number 5
  142. helm-default-external-file-browser "thunar"
  143. helm-pdfgrep-default-read-command "evince --page-label=%p '%f'"
  144. ;helm-ff-transformer-show-only-basename t
  145. helm-ff-auto-update-initial-value t
  146. helm-grep-default-command "ack -Hn --smart-case --no-group %e %p %f"
  147. helm-grep-default-recurse-command "ack -H --smart-case --no-group %e %p %f"
  148. ;; Allow skipping unwanted files specified in ~/.gitignore_global
  149. ;; Added in my .gitconfig with "git config --global core.excludesfile ~/.gitignore_global"
  150. helm-ls-git-grep-command "git grep -n%cH --color=always --exclude-standard --no-index --full-name -e %p %f"
  151. helm-default-zgrep-command "zgrep --color=always -a -n%cH -e %p %f"
  152. ;helm-pdfgrep-default-command "pdfgrep --color always -niH %s %s"
  153. helm-reuse-last-window-split-state t
  154. ;helm-split-window-default-side 'below
  155. ;helm-split-window-in-side-p t
  156. ;helm-echo-input-in-header-line t
  157. helm-always-two-windows t
  158. ;helm-persistent-action-use-special-display t
  159. helm-buffers-favorite-modes (append helm-buffers-favorite-modes
  160. '(picture-mode artist-mode))
  161. helm-ls-git-status-command 'magit-status
  162. ;helm-never-delay-on-input nil
  163. ;helm-candidate-number-limit 200
  164. helm-M-x-requires-pattern 0
  165. helm-dabbrev-cycle-threshold 5
  166. helm-surfraw-duckduckgo-url "https://duckduckgo.com/?q=%s&ke=-1&kf=fw&kl=fr-fr&kr=b&k1=-1&k4=-1"
  167. ;helm-surfraw-default-browser-function 'w3m-browse-url
  168. helm-boring-file-regexp-list '("\\.git$" "\\.hg$" "\\.svn$" "\\.CVS$" "\\._darcs$" "\\.la$" "\\.o$" "\\.i$")
  169. ;helm-mode-handle-completion-in-region t
  170. ;helm-moccur-always-search-in-current t
  171. ;helm-tramp-verbose 6
  172. helm-buffer-skip-remote-checking t
  173. ;helm-ff-file-name-history-use-recentf t
  174. ;helm-follow-mode-persistent t
  175. helm-apropos-fuzzy-match t
  176. helm-M-x-fuzzy-match t
  177. helm-lisp-fuzzy-completion t
  178. ;helm-locate-fuzzy-match t
  179. helm-completion-in-region-fuzzy-match t
  180. helm-move-to-line-cycle-in-source t
  181. ido-use-virtual-buffers t ; Needed in helm-buffers-list
  182. helm-tramp-verbose 6
  183. helm-buffers-fuzzy-matching t
  184. helm-locate-command "locate %s -e -A --regex %s"
  185. helm-org-headings-fontify t
  186. helm-autoresize-max-height 80 ; it is %.
  187. helm-autoresize-min-height 20 ; it is %.
  188. helm-buffers-to-resize-on-pa '("*helm apropos*" "*helm ack-grep*"
  189. "*helm grep*" "*helm occur*"
  190. "*helm multi occur*" "*helm lsgit*"
  191. "*helm git-grep*" "*helm hg files*"
  192. "*helm imenu*" "*helm imenu all*"
  193. "*helm gid*" "*helm semantic/imenu*")
  194. fit-window-to-buffer-horizontally 1
  195. helm-open-github-closed-issue-since 7
  196. helm-search-suggest-action-wikipedia-url
  197. "https://fr.wikipedia.org/wiki/Special:Search?search=%s"
  198. helm-wikipedia-suggest-url
  199. "http://fr.wikipedia.org/w/api.php?action=opensearch&search="
  200. helm-wikipedia-summary-url
  201. "http://fr.wikipedia.org/w/api.php?action=parse&format=json&prop=text&section=0&page=")
  202. ;; Avoid hitting forbidden directory .gvfs when using find.
  203. (add-to-list 'completion-ignored-extensions ".gvfs/")
  204. ;;; Hide minibuffer
  205. ;;
  206. ;; (add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
  207. ;;; Toggle grep program
  208. (defun eselect-grep ()
  209. (interactive)
  210. (when (y-or-n-p (format "Current grep program is %s, switching? "
  211. (helm-grep-command)))
  212. (if (helm-grep-use-ack-p)
  213. (setq helm-grep-default-command
  214. "grep --color=always -d skip %e -n%cH -e %p %f"
  215. helm-grep-default-recurse-command
  216. "grep --color=always -d recurse %e -n%cH -e %p %f")
  217. (setq helm-grep-default-command
  218. "ack-grep -Hn --smart-case --no-group %e %p %f"
  219. helm-grep-default-recurse-command
  220. "ack-grep -H --smart-case --no-group %e %p %f"))
  221. (message "Switched to %s" (helm-grep-command))))
  222. ;;; Debugging
  223. (defun helm-debug-toggle ()
  224. (interactive)
  225. (setq helm-debug (not helm-debug))
  226. (message "Helm Debug is now %s"
  227. (if helm-debug "Enabled" "Disabled")))
  228. (defun helm-ff-candidates-lisp-p (candidate)
  229. (cl-loop for cand in (helm-marked-candidates)
  230. always (string-match "\.el$" cand)))
  231. ;;; Modify source attributes
  232. ;; Add actions to `helm-source-find-files' IF:
  233. (defmethod helm-setup-user-source ((source helm-source-ffiles))
  234. (helm-source-add-action-to-source-if
  235. "Byte compile file(s) async"
  236. 'async-byte-compile-file
  237. source
  238. 'helm-ff-candidates-lisp-p))
  239. (defmethod helm-setup-user-source ((source helm-source-buffers))
  240. (set-slot-value source 'candidate-number-limit 200))
  241. ;;; Psession windows
  242. (defun helm-psession-windows ()
  243. (interactive)
  244. (helm :sources (helm-build-sync-source "Psession windows"
  245. :candidates (lambda ()
  246. (sort (mapcar 'car psession--winconf-alist) #'string-lessp))
  247. :action (helm-make-actions
  248. "Restore" 'psession-restore-winconf
  249. "Delete" 'psession-delete-winconf))
  250. :buffer "*helm psession*"))
  251. ;;; helm dictionary
  252. (setq helm-dictionary-database "~/helm-dictionary/dic-en-fr.iso")
  253. (setq helm-dictionary-online-dicts '(("translate.reference.com en->fr" .
  254. "http://translate.reference.com/translate?query=%s&src=en&dst=fr")
  255. ("translate.reference.com fr->en" .
  256. "http://translate.reference.com/translate?query=%s&src=fr&dst=en")))
  257. ;; --------------------------------------------------------------------
  258. ;; 下面配置helm-swoop.el,快速搜索
  259. ;; https://github.com/ShingoFukuyama/helm-swoop
  260. ;; --------------------------------------------------------------------
  261. ;; helm from https://github.com/emacs-helm/helm
  262. (require 'helm)
  263. ;; Locate the helm-swoop folder to your path
  264. ;; (add-to-list 'load-path "~/.emacs.d/elisp/helm-swoop")
  265. (require 'helm-swoop)
  266. ;; Change the keybinds to whatever you like :)
  267. (global-set-key (kbd "M-i") 'helm-swoop)
  268. (global-set-key (kbd "C-S-s") 'helm-swoop)
  269. (global-set-key (kbd "M-I") 'helm-swoop-back-to-last-point)
  270. (global-set-key (kbd "C-c M-i") 'helm-multi-swoop)
  271. (global-set-key (kbd "C-x M-i") 'helm-multi-swoop-all)
  272. ;; When doing isearch, hand the word over to helm-swoop
  273. (define-key isearch-mode-map (kbd "M-i") 'helm-swoop-from-isearch)
  274. ;; From helm-swoop to helm-multi-swoop-all
  275. (define-key helm-swoop-map (kbd "M-i") 'helm-multi-swoop-all-from-helm-swoop)
  276. ;; When doing evil-search, hand the word over to helm-swoop
  277. ;; (define-key evil-motion-state-map (kbd "M-i") 'helm-swoop-from-evil-search)
  278. ;; Instead of helm-multi-swoop-all, you can also use helm-multi-swoop-current-mode
  279. (define-key helm-swoop-map (kbd "M-m") 'helm-multi-swoop-current-mode-from-helm-swoop)
  280. ;; Move up and down like isearch
  281. (define-key helm-swoop-map (kbd "C-r") 'helm-previous-line)
  282. (define-key helm-swoop-map (kbd "C-s") 'helm-next-line)
  283. (define-key helm-multi-swoop-map (kbd "C-r") 'helm-previous-line)
  284. (define-key helm-multi-swoop-map (kbd "C-s") 'helm-next-line)
  285. ;; Save buffer when helm-multi-swoop-edit complete
  286. (setq helm-multi-swoop-edit-save t)
  287. ;; If this value is t, split window inside the current window
  288. (setq helm-swoop-split-with-multiple-windows nil)
  289. ;; Split direcion. 'split-window-vertically or 'split-window-horizontally
  290. (setq helm-swoop-split-direction 'split-window-vertically)
  291. ;; If nil, you can slightly boost invoke speed in exchange for text color
  292. (setq helm-swoop-speed-or-color nil)
  293. ;; ;; Go to the opposite side of line from the end or beginning of line
  294. (setq helm-swoop-move-to-line-cycle t)
  295. ;; Optional face for line numbers
  296. ;; Face name is `helm-swoop-line-number-face`
  297. (setq helm-swoop-use-line-number-face t)
  298. ;; use search query at the cursor (default)
  299. (setq helm-swoop-pre-input-function
  300. (lambda () (thing-at-point 'symbol)))
  301. ;; disable pre-input
  302. (setq helm-swoop-pre-input-function
  303. (lambda () ""))
  304. ;; match only for symbol
  305. (setq helm-swoop-pre-input-function
  306. (lambda () (format "\\_<%s\\_> " (thing-at-point 'symbol))))
  307. ;; Always use the previous search for helm. Remember C-<backspace> will delete entire line
  308. (setq helm-swoop-pre-input-function
  309. (lambda () (if (boundp 'helm-swoop-pattern)
  310. helm-swoop-pattern "")))
  311. ;; If there is no symbol at the cursor, use the last used words instead.
  312. (setq helm-swoop-pre-input-function
  313. (lambda ()
  314. (let (($pre-input (thing-at-point 'symbol)))
  315. (if (eq (length $pre-input) 0)
  316. helm-swoop-pattern ;; this variable keeps the last used words
  317. $pre-input))))
  318. ;; -----------------------------------------------------------------------------
  319. ;; helm-dash这个文档插件,可以有时间看看,很有用
  320. ;; https://github.com/areina/helm-dash
  321. ;; -----------------------------------------------------------------------------
  322. (provide 'init-helm-aborn)
  323. ;;; init-helm-thierry.el ends here