ReverseFlux

helm-thierry

Feb 7th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.79 KB | None | 0 0
  1. ;;; init-helm-thierry.el --- My startup file for helm. -*- lexical-binding: t -*-
  2. ;;; Code:
  3.  
  4. ;;; Load all autoloads for helm and its extensions
  5. ;;
  6. (require 'helm-config)
  7. (load "/home/thierry/elisp/helm-extensions/helm-extensions-autoloads.el")
  8.  
  9. ;;; Enable Modes (helm-mode is loading nearly everything).
  10. ;;
  11. (use-package helm-mode
  12. :config (helm-mode 1))
  13.  
  14. (use-package helm-adaptive
  15. :config (helm-adaptive-mode 1))
  16.  
  17. (use-package helm-ring
  18. :config (helm-push-mark-mode 1))
  19.  
  20. (use-package helm-utils
  21. ;; Popup buffer-name or filename in grep/moccur/imenu-all etc...
  22. :config (helm-popup-tip-mode 1))
  23.  
  24. (use-package helm-sys
  25. :config (helm-top-poll-mode 1))
  26. ;;;; Test Sources or new helm code.
  27. ;; !!!WARNING EXPERIMENTAL!!!
  28.  
  29. (defun helm/version-1 ()
  30. (with-temp-buffer
  31. (insert-file-contents (find-library-name "helm-core-pkg"))
  32. (goto-char (point-min))
  33. (when (re-search-forward
  34. "\\([0-9]+?\\)\\.?\\([0-9]*\\)\\.?\\([0-9]*\\)\\.?[0-9]*" nil t)
  35. (match-string-no-properties 0))))
  36.  
  37. ;; Helm version: 1.9.3
  38. (defun helm/version (arg)
  39. (interactive "P")
  40. (let ((version-str (format "Helm version: %s" (helm/version-1))))
  41. (if arg (insert version-str) (message version-str))))
  42.  
  43. (defun helm/git-version ()
  44. (shell-command-to-string
  45. "git log --pretty='format:%H' -1"))
  46.  
  47. (defun helm/turn-on-header-line ()
  48. (interactive)
  49. (setq helm-echo-input-in-header-line t)
  50. (setq helm-split-window-in-side-p t)
  51. (helm-autoresize-mode -1)
  52. (add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
  53. )
  54.  
  55. (defun helm/turn-off-header-line ()
  56. (interactive)
  57. (setq helm-echo-input-in-header-line nil)
  58. ;;(helm-autoresize-mode 1)
  59. (setq helm-split-window-in-side-p nil)
  60. (remove-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
  61. )
  62.  
  63. (defun helm/occur-which-func ()
  64. (interactive)
  65. (with-current-buffer
  66. (or (helm-aif (with-helm-buffer
  67. (window-buffer helm-persistent-action-display-window))
  68. (and (null (minibufferp it)) it))
  69. helm-current-buffer)
  70. (when (eq major-mode 'emacs-lisp-mode)
  71. (message "[%s]" (which-function)))))
  72.  
  73. (define-key helm-moccur-map (kbd "C-M-a") 'helm/occur-which-func)
  74. (define-key helm-grep-map (kbd "C-M-a") 'helm/occur-which-func)
  75.  
  76. ;; Show the visibles buffers on top of list (issue #1301)
  77.  
  78. (defun helm/modify-ido-temp-list ()
  79. (let ((bl (mapcar #'buffer-name (buffer-list (selected-frame)))))
  80. (setq ido-temp-list (nconc (cdr bl) (list (car bl))))))
  81. ;;(add-hook 'ido-make-buffer-list-hook 'helm/modify-ido-temp-list)
  82.  
  83. (defun helm-ag-find-file-init (directory)
  84. (start-process "ag-find-file" nil "ag" "--hidden" "-g" helm-pattern directory))
  85.  
  86. (defclass helm-ag-find-file-class (helm-source-async)
  87. ((filtered-candidate-transformer
  88. :initform
  89. (lambda (candidates _source)
  90. (cl-loop for c in candidates
  91. collect (helm--ansi-color-apply c))))
  92. (requires-pattern :initform 2)
  93. (candidate-number-limit :initform 99999)))
  94.  
  95. (defun helm-ag-find-file-1 (directory)
  96. (helm :sources (helm-make-source "AG find files" 'helm-ag-find-file-class
  97. :candidates-process (lambda ()
  98. (helm-ag-find-file-init directory))
  99. :action (helm-actions-from-type-file))
  100. :buffer "*helm ag find file*"))
  101.  
  102. (defun helm-ag-find-file ()
  103. (interactive)
  104. (helm-ag-find-file-1 (expand-file-name default-directory)))
  105.  
  106. (defun helm-ff-ag-find-files (_candidate)
  107. (helm-ag-find-file-1 helm-ff-default-directory))
  108.  
  109. (defun helm-ff-run-ag-find-files ()
  110. (interactive)
  111. (with-helm-alive-p
  112. (helm-exit-and-execute-action 'helm-ff-ag-find-files)))
  113.  
  114. (define-key helm-find-files-map (kbd "C-c f") 'helm-ff-run-ag-find-files)
  115.  
  116. ;;; Helm-command-map
  117. ;;
  118. ;;
  119. (define-key helm-command-map (kbd "g") 'helm-apt)
  120. (define-key helm-command-map (kbd "z") 'helm-complex-command-history)
  121. (define-key helm-command-map (kbd "w") 'helm-w3m-bookmarks)
  122. (define-key helm-command-map (kbd "x") 'helm-firefox-bookmarks)
  123. (define-key helm-command-map (kbd "#") 'helm-emms)
  124. (define-key helm-command-map (kbd "I") 'helm-imenu-in-all-buffers)
  125.  
  126. ;;; Global-map
  127. ;;
  128. ;;
  129. (global-set-key (kbd "M-x") 'undefined)
  130. (global-set-key (kbd "M-x") 'helm-M-x)
  131. (global-set-key (kbd "M-y") 'helm-show-kill-ring)
  132. (global-set-key (kbd "C-x C-f") 'helm-find-files)
  133. (global-set-key (kbd "C-c <SPC>") 'helm-all-mark-rings)
  134. (global-set-key (kbd "C-x r b") 'helm-filtered-bookmarks)
  135. (global-set-key (kbd "C-h r") 'helm-info-emacs)
  136. (global-set-key (kbd "C-:") 'helm-eval-expression-with-eldoc)
  137. (global-set-key (kbd "C-,") 'helm-calcul-expression)
  138. (global-set-key (kbd "C-h d") 'helm-info-at-point)
  139. (global-set-key (kbd "C-h i") 'helm-info)
  140. (global-set-key (kbd "C-x C-d") 'helm-browse-project)
  141. (global-set-key (kbd "<f1>") 'helm-resume)
  142. (global-set-key (kbd "C-h C-f") 'helm-apropos)
  143. (global-set-key (kbd "C-h a") 'helm-apropos)
  144. (global-set-key (kbd "<f5> s") 'helm-find)
  145. (global-set-key (kbd "S-<f2>") 'helm-execute-kmacro)
  146. (global-set-key (kbd "C-c i") 'helm-imenu-in-all-buffers)
  147. (global-set-key (kbd "<f11> o") 'helm-org-agenda-files-headings)
  148. (global-set-key (kbd "C-s") 'helm-occur)
  149. (define-key global-map [remap jump-to-register] 'helm-register)
  150. (define-key global-map [remap list-buffers] 'helm-mini)
  151. (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
  152. (define-key global-map [remap find-tag] 'helm-etags-select)
  153. (define-key global-map [remap xref-find-definitions] 'helm-etags-select)
  154. (define-key global-map (kbd "M-g a") 'helm-do-grep-ag)
  155. (define-key global-map (kbd "M-g g") 'helm-grep-do-git-grep)
  156. (define-key global-map (kbd "M-g i") 'helm-gid)
  157. (define-key global-map (kbd "C-x r p") 'helm-projects-history)
  158. (define-key global-map (kbd "C-x r c") 'helm-addressbook-bookmarks)
  159.  
  160. (helm-multi-key-defun helm-multi-lisp-complete-at-point
  161. "Multi key function for completion in emacs lisp buffers.
  162. First call indent, second complete symbol, third complete fname."
  163. '(helm-lisp-indent
  164. helm-lisp-completion-at-point
  165. helm-complete-file-name-at-point)
  166. 0.3)
  167.  
  168. (if (and (boundp 'tab-always-indent)
  169. (eq tab-always-indent 'complete)
  170. (boundp 'completion-in-region-function))
  171. (progn
  172. (define-key lisp-interaction-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  173. (define-key emacs-lisp-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  174.  
  175. ;; lisp complete. (Rebind M-<tab>)
  176. (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
  177. (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
  178.  
  179. (define-key lisp-interaction-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  180. (define-key emacs-lisp-mode-map [remap indent-for-tab-command] 'helm-multi-lisp-complete-at-point)
  181.  
  182. ;; lisp complete. (Rebind M-<tab>)
  183. (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
  184. (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
  185.  
  186. (unless (boundp 'completion-in-region-function)
  187. (add-hook 'ielm-mode-hook
  188. #'(lambda ()
  189. (define-key ielm-map [remap completion-at-point] 'helm-lisp-completion-at-point))))
  190.  
  191. ;;; helm find files
  192. ;;
  193. (define-key helm-find-files-map (kbd "C-d") 'helm-ff-persistent-delete)
  194. (define-key helm-buffer-map (kbd "C-d") 'helm-buffer-run-kill-persistent)
  195. (define-key helm-find-files-map (kbd "C-/") 'helm-ff-run-find-sh-command)
  196.  
  197. ;;; Describe key-bindings
  198. ;;
  199. ;;
  200. (helm-descbinds-mode 1) ; C-h b, C-x C-h
  201.  
  202. ;;; Helm-variables
  203. ;;
  204. ;;
  205. (setq helm-net-prefer-curl nil
  206. helm-kill-ring-threshold 1
  207. helm-raise-command "wmctrl -xa %s"
  208. helm-scroll-amount 4
  209. helm-idle-delay 0.01
  210. helm-input-idle-delay 0.01
  211. helm-default-external-file-browser "thunar"
  212. helm-pdfgrep-default-read-command "evince --page-label=%p '%f'"
  213. helm-ff-auto-update-initial-value t
  214. helm-grep-default-command "ack-grep -Hn --color --smart-case --no-group %e %p %f"
  215. helm-grep-default-recurse-command "ack-grep -H --color --smart-case --no-group %e %p %f"
  216. helm-reuse-last-window-split-state t
  217. helm-always-two-windows t
  218. helm-split-window-in-side-p nil
  219. helm-show-action-window-other-window 'left
  220. helm-buffers-favorite-modes (append helm-buffers-favorite-modes '(picture-mode artist-mode))
  221. helm-ls-git-status-command 'magit-status-internal
  222. helm-M-x-requires-pattern 0
  223. helm-dabbrev-cycle-threshold 5
  224. helm-surfraw-duckduckgo-url "https://duckduckgo.com/?q=%s&ke=-1&kf=fw&kl=fr-fr&kr=b&k1=-1&k4=-1"
  225. helm-google-suggest-search-url helm-surfraw-duckduckgo-url
  226. helm-boring-file-regexp-list '("\\.git/" "\\.hg/" "\\.svn/" "\\.CVS/" "\\._darcs/" "\\.la$" "\\.o$" "\\.i$"
  227. "\\.steam/" "\\undo-tree-history/" "\\.Private/" "\\.encrypted/" "\\emacs_backup/")
  228. helm-buffer-skip-remote-checking t
  229. helm-apropos-fuzzy-match t
  230. helm-M-x-fuzzy-match t
  231. helm-lisp-fuzzy-completion t
  232. helm-completion-in-region-fuzzy-match t
  233. helm-buffers-fuzzy-matching t
  234. helm-locate-fuzzy-match t
  235. helm-move-to-line-cycle-in-source t
  236. ido-use-virtual-buffers t ; Needed in helm-buffers-list
  237. helm-tramp-verbose 6
  238. helm-org-headings-fontify t
  239. helm-autoresize-max-height 80 ; it is %.
  240. helm-autoresize-min-height 20 ; it is %.
  241. fit-window-to-buffer-horizontally 1
  242. helm-open-github-closed-issue-since 30
  243. helm-highlight-matches-around-point-max-lines 30
  244. helm-search-suggest-action-wikipedia-url
  245. "https://fr.wikipedia.org/wiki/Special:Search?search=%s"
  246. helm-wikipedia-suggest-url
  247. "https://fr.wikipedia.org/w/api.php?action=opensearch&search="
  248. helm-wikipedia-summary-url
  249. "https://fr.wikipedia.org/w/api.php?action=parse&format=json&prop=text&section=0&page="
  250. helm-firefox-show-structure nil
  251. helm-turn-on-recentf nil
  252. helm-mini-default-sources '(helm-source-buffers-list helm-source-buffer-not-found)
  253. helm-debug-root-directory "/home/thierry/tmp/helm-debug"
  254. helm-follow-mode-persistent t
  255. )
  256.  
  257. ;; Avoid hitting forbidden directory .gvfs when using find.
  258. (add-to-list 'completion-ignored-extensions ".gvfs/")
  259.  
  260. ;;; Toggle grep program
  261. ;;
  262. ;;
  263. (defun helm/eselect-grep ()
  264. (interactive)
  265. (when (y-or-n-p (format "Current grep program is %s, switching? "
  266. (helm-grep-command)))
  267. (if (helm-grep-use-ack-p)
  268. (setq helm-grep-default-command
  269. "grep --color=always -d skip %e -n%cH -e %p %f"
  270. helm-grep-default-recurse-command
  271. "grep --color=always -d recurse %e -n%cH -e %p %f")
  272. (setq helm-grep-default-command
  273. "ack-grep -Hn --color --smart-case --no-group %e %p %f"
  274. helm-grep-default-recurse-command
  275. "ack-grep -H --color --smart-case --no-group %e %p %f"))
  276. (message "Switched to %s" (helm-grep-command))))
  277.  
  278. ;;; Debugging
  279. ;;
  280. ;;
  281. (defun helm/debug-toggle ()
  282. (interactive)
  283. (setq helm-debug (not helm-debug))
  284. (message "Helm Debug is now %s"
  285. (if helm-debug "Enabled" "Disabled")))
  286.  
  287. (defun helm/ff-candidates-lisp-p (candidate)
  288. (cl-loop for cand in (helm-marked-candidates)
  289. always (string-match "\.el$" cand)))
  290.  
  291. ;;; Modify source attributes
  292. ;;
  293. ;; Add actions to `helm-source-find-files' IF:
  294. (defmethod helm-setup-user-source ((source helm-source-ffiles))
  295. "Adds additional actions to `helm-find-files'.
  296. - Byte compile file(s) async.
  297. - Byte recompile directory.
  298. - Magit status."
  299. (helm-source-add-action-to-source-if
  300. "Byte compile file(s) async"
  301. 'tv/async-byte-compile-file
  302. source
  303. 'helm/ff-candidates-lisp-p)
  304. (helm-source-add-action-to-source-if
  305. "Byte recompile directory"
  306. 'async-byte-recompile-directory
  307. source
  308. 'file-directory-p)
  309. (helm-source-add-action-to-source-if
  310. "Magit status"
  311. (lambda (_candidate)
  312. (funcall helm-ls-git-status-command
  313. helm-ff-default-directory))
  314. source
  315. (lambda (candidate)
  316. (and (not (string-match-p ffap-url-regexp candidate))
  317. (locate-dominating-file helm-ff-default-directory
  318. ".git")))
  319. 1))
  320.  
  321. (defmethod helm-setup-user-source ((source helm-source-buffers))
  322. "Adds additional actions to `helm-source-buffers-list'.
  323. - Magit status."
  324. (setf (slot-value source 'candidate-number-limit) 300)
  325. (helm-source-add-action-to-source-if
  326. "Magit status"
  327. (lambda (candidate)
  328. (funcall helm-ls-git-status-command
  329. (with-current-buffer candidate default-directory)))
  330. source
  331. (lambda (candidate)
  332. (locate-dominating-file (with-current-buffer candidate default-directory)
  333. ".git"))
  334. 1))
  335.  
  336. ;;; helm dictionary
  337. ;;
  338. (setq helm-dictionary-database "~/helm-dictionary/dic-en-fr.iso")
  339. (setq helm-dictionary-online-dicts '(("translate.reference.com en->fr" .
  340. "http://translate.reference.com/translate?query=%s&src=en&dst=fr")
  341. ("translate.reference.com fr->en" .
  342. "http://translate.reference.com/translate?query=%s&src=fr&dst=en")))
  343.  
  344.  
  345. (provide 'init-helm-thierry)
  346.  
  347. ;;; init-helm-thierry.el ends here
Advertisement
Add Comment
Please, Sign In to add comment