2017-05-28 18:39:25 +02:00
|
|
|
;;; Helm
|
2016-10-14 14:03:30 +02:00
|
|
|
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; TODO: helm-ff should allow opening several marks externally, e.g. sxiv for
|
|
|
|
;;; pics. See
|
2017-10-15 14:55:49 +02:00
|
|
|
;;; https://github.com/emacs-helm/helm/wiki/Find-Files#open-files-externally.
|
|
|
|
;;; What about the default program? It currently defaults to ~/.mailcap, which is
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; not so customizable. Would ranger's rifle be useful here? See
|
2017-10-15 14:55:49 +02:00
|
|
|
;;; https://github.com/emacs-helm/helm/issues/1796. There is the `openwith' package.
|
2017-10-10 17:35:48 +02:00
|
|
|
|
|
|
|
;;; TODO: Batch-open torrent files automatically. Add to mailcap? Same as
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; above, C-c C-x does not allow for opening several files at once.
|
2017-07-28 09:12:25 +02:00
|
|
|
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; TODO: helm-find in big folders sometimes leads bad results, like exact match
|
|
|
|
;;; not appearing first. Better sorting?
|
2017-10-10 17:35:48 +02:00
|
|
|
|
|
|
|
;;; TODO: Implement alternating-color multiline lists.
|
|
|
|
;;; See https://github.com/emacs-helm/helm/issues/1790.
|
2017-07-28 09:12:25 +02:00
|
|
|
|
2017-11-26 22:37:24 +01:00
|
|
|
;;; TODO: Impement helm-portage (currently helm-gentoo).
|
|
|
|
;;; TODO: Implement helm-pacman.
|
|
|
|
|
2017-10-19 15:56:29 +02:00
|
|
|
(when (require 'linum-relative nil t)
|
|
|
|
(helm-linum-relative-mode 1))
|
2017-10-15 14:55:49 +02:00
|
|
|
|
2016-06-10 13:53:40 +02:00
|
|
|
(when (require 'helm-descbinds nil t)
|
|
|
|
(helm-descbinds-mode))
|
|
|
|
|
2017-05-13 10:59:19 +02:00
|
|
|
(when (require 'wgrep-helm nil t)
|
2017-06-18 15:12:32 +02:00
|
|
|
(setq wgrep-auto-save-buffer t
|
|
|
|
wgrep-enable-key (kbd "C-x C-q")))
|
2017-05-13 10:59:19 +02:00
|
|
|
|
2017-10-24 18:11:19 +02:00
|
|
|
(when (require 'helm-ls-git nil t)
|
|
|
|
;; `helm-source-ls-git' must be defined manually.
|
|
|
|
;; See https://github.com/emacs-helm/helm-ls-git/issues/34.
|
|
|
|
(setq helm-source-ls-git
|
|
|
|
(and (memq 'helm-source-ls-git helm-ls-git-default-sources)
|
|
|
|
(helm-make-source "Git files" 'helm-ls-git-source
|
|
|
|
:fuzzy-match helm-ls-git-fuzzy-match))))
|
2017-05-28 19:06:41 +02:00
|
|
|
|
2016-06-10 13:53:40 +02:00
|
|
|
(helm-mode 1)
|
2017-05-28 18:39:25 +02:00
|
|
|
;; (helm-autoresize-mode 1)
|
2016-06-10 13:53:40 +02:00
|
|
|
(add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)
|
|
|
|
|
2017-08-02 09:07:22 +02:00
|
|
|
;;; This makes the copy and rename operations asynchronous.
|
|
|
|
(dired-async-mode)
|
|
|
|
|
2017-10-24 18:12:09 +02:00
|
|
|
;;; Generic configuration.
|
2017-06-18 15:12:32 +02:00
|
|
|
(setq
|
|
|
|
helm-follow-mode-persistent t
|
|
|
|
helm-reuse-last-window-split-state t
|
|
|
|
helm-display-header-line nil
|
|
|
|
helm-findutils-search-full-path t
|
2017-06-28 17:03:24 +02:00
|
|
|
helm-show-completion-use-special-display nil
|
2017-06-29 21:40:42 +02:00
|
|
|
helm-completion-mode-string ""
|
2017-10-10 17:35:48 +02:00
|
|
|
helm-dwim-target 'completion
|
2017-06-18 15:12:32 +02:00
|
|
|
|
|
|
|
helm-apropos-fuzzy-match t
|
|
|
|
helm-buffers-fuzzy-matching t
|
2017-06-18 21:05:31 +02:00
|
|
|
helm-eshell-fuzzy-match t
|
2017-06-18 15:12:32 +02:00
|
|
|
helm-imenu-fuzzy-match t
|
2017-06-18 21:05:31 +02:00
|
|
|
helm-M-x-fuzzy-match t
|
2017-10-18 19:18:54 +02:00
|
|
|
helm-recentf-fuzzy-match t
|
|
|
|
|
2017-11-07 12:19:07 +01:00
|
|
|
;; https://github.com/emacs-helm/helm/issues/1910
|
2017-11-02 13:10:27 +01:00
|
|
|
helm-buffers-end-truncated-string "…"
|
2017-11-07 12:19:07 +01:00
|
|
|
helm-buffer-max-length 22
|
2017-11-02 13:10:27 +01:00
|
|
|
|
2017-10-18 19:18:54 +02:00
|
|
|
helm-window-show-buffers-function 'helm-window-mosaic-fn
|
|
|
|
helm-window-prefer-horizontal-split t)
|
2016-06-10 13:53:40 +02:00
|
|
|
|
2017-10-19 15:56:08 +02:00
|
|
|
(defun helm-split-window-combined-fn (window)
|
|
|
|
"Helm window splitting that combined most standard features.
|
|
|
|
|
|
|
|
- With C-u, split inside. With C-u C-u, use same window.
|
|
|
|
- Else use biggest other window when available.
|
|
|
|
- Else split horizontally if width>height, vertically otherwise."
|
|
|
|
(cond
|
|
|
|
((or (minibufferp helm-current-buffer)
|
|
|
|
(and
|
|
|
|
(not (one-window-p t))
|
|
|
|
(not (equal current-prefix-arg '(4)))
|
|
|
|
(not (equal current-prefix-arg '(16)))))
|
|
|
|
;; Find biggest window.
|
|
|
|
(let (biggest (maxarea 0))
|
|
|
|
(dolist (w (window-list))
|
|
|
|
(unless (eq w (selected-window))
|
|
|
|
(let ((area (* (window-pixel-width w) (window-pixel-height w))))
|
|
|
|
(when (> area maxarea)
|
|
|
|
(setq maxarea area
|
|
|
|
biggest w)))))
|
|
|
|
biggest))
|
|
|
|
((equal current-prefix-arg '(16))
|
|
|
|
;; Same window.
|
|
|
|
(selected-window))
|
|
|
|
(t
|
|
|
|
;; If split inside or if unique window.
|
|
|
|
(split-window (selected-window) nil
|
|
|
|
(if (> (window-pixel-width) (window-pixel-height))
|
|
|
|
'right
|
|
|
|
'below)))))
|
2017-10-24 18:12:09 +02:00
|
|
|
(setq helm-split-window-preferred-function 'helm-split-window-combined-fn)
|
2017-10-19 15:56:08 +02:00
|
|
|
|
2017-06-18 17:58:35 +02:00
|
|
|
;;; From https://github.com/emacs-helm/helm/issues/362.
|
2017-10-10 18:43:05 +02:00
|
|
|
;;; This is not perfect with evil mode as the cursor type is not right in the
|
|
|
|
;;; header line and the evil cursor remains in the minibuffer.
|
2017-06-18 17:58:35 +02:00
|
|
|
;;; https://emacs.stackexchange.com/questions/17058/change-cursor-type-in-helm-header-line#17097
|
|
|
|
(setq helm-echo-input-in-header-line t)
|
|
|
|
(defun helm-hide-minibuffer-maybe ()
|
|
|
|
(when (with-helm-buffer helm-echo-input-in-header-line)
|
|
|
|
(let ((ov (make-overlay (point-min) (point-max) nil nil t)))
|
|
|
|
(overlay-put ov 'window (selected-window))
|
|
|
|
(overlay-put ov 'face (let ((bg-color (face-background 'default nil)))
|
|
|
|
`(:background ,bg-color :foreground ,bg-color)))
|
|
|
|
(setq-local cursor-type nil))))
|
|
|
|
(add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
|
|
|
|
|
2017-07-28 09:12:25 +02:00
|
|
|
;;; Add bindings to `helm-apropos`. TODO: Does not work most of the times.
|
2017-05-29 11:57:56 +02:00
|
|
|
;;; https://github.com/emacs-helm/helm/issues/1140
|
|
|
|
(defun helm-def-source--emacs-commands (&optional default)
|
|
|
|
(helm-build-in-buffer-source "Commands"
|
|
|
|
:init `(lambda ()
|
|
|
|
(helm-apropos-init 'commandp ,default))
|
|
|
|
:fuzzy-match helm-apropos-fuzzy-match
|
|
|
|
:filtered-candidate-transformer (and (null helm-apropos-fuzzy-match)
|
|
|
|
'helm-apropos-default-sort-fn)
|
|
|
|
:candidate-transformer 'helm-M-x-transformer-1
|
|
|
|
:nomark t
|
|
|
|
:action '(("Describe Function" . helm-describe-function)
|
|
|
|
("Find Function" . helm-find-function)
|
|
|
|
("Info lookup" . helm-info-lookup-symbol))))
|
|
|
|
|
2017-05-28 19:06:41 +02:00
|
|
|
;;; Make `helm-mini' almighty.
|
2017-09-11 19:29:54 +02:00
|
|
|
(require 'helm-bookmark)
|
2017-10-24 18:11:19 +02:00
|
|
|
(setq helm-mini-default-sources `(helm-source-buffers-list
|
2017-05-28 19:06:41 +02:00
|
|
|
helm-source-recentf
|
2017-10-24 18:11:19 +02:00
|
|
|
,(when (boundp 'helm-source-ls-git) 'helm-source-ls-git)
|
2017-05-28 19:06:41 +02:00
|
|
|
helm-source-bookmarks
|
|
|
|
helm-source-bookmark-set
|
|
|
|
helm-source-buffer-not-found))
|
|
|
|
|
2017-06-12 22:26:50 +02:00
|
|
|
;;; Eshell
|
2017-06-18 20:58:21 +02:00
|
|
|
(defun helm/eshell-set-keys ()
|
|
|
|
(define-key eshell-mode-map [remap eshell-pcomplete] 'helm-esh-pcomplete)
|
2017-10-28 13:22:01 +02:00
|
|
|
(define-key eshell-mode-map (kbd "M-p") 'helm-eshell-history)
|
2017-11-05 11:04:28 +01:00
|
|
|
(define-key eshell-mode-map (kbd "M-s") nil) ; Useless when we have 'helm-eshell-history.
|
2017-10-28 13:22:01 +02:00
|
|
|
(define-key eshell-mode-map (kbd "M-s f") 'helm-eshell-prompts-all))
|
2017-06-18 20:58:21 +02:00
|
|
|
(add-hook 'eshell-mode-hook 'helm/eshell-set-keys)
|
2017-06-12 22:26:50 +02:00
|
|
|
|
2017-10-08 20:36:28 +02:00
|
|
|
;;; TODO: Use helm-ff history in helm file completion.
|
|
|
|
;;; https://github.com/emacs-helm/helm/issues/1118
|
2017-08-01 20:55:50 +02:00
|
|
|
;; (define-key helm-read-file-map (kbd "M-p") 'helm-ff-run-switch-to-history)
|
|
|
|
|
2017-05-28 18:39:25 +02:00
|
|
|
;;; Do not exclude any files from 'git grep'.
|
2016-09-23 15:24:15 +02:00
|
|
|
(setq helm-grep-git-grep-command "git --no-pager grep -n%cH --color=always --full-name -e %p -- %f")
|
|
|
|
|
|
|
|
(defun helm-grep-git-or-ag (arg)
|
2016-10-12 05:43:03 +02:00
|
|
|
"Run `helm-grep-do-git-grep' if possible; fallback to `helm-do-grep-ag' otherwise.
|
|
|
|
Requires `call-process-to-string' from `functions'."
|
2016-09-23 15:24:15 +02:00
|
|
|
(interactive "P")
|
|
|
|
(require 'vc)
|
2016-10-12 05:43:03 +02:00
|
|
|
(require 'functions)
|
|
|
|
(if (and (vc-find-root default-directory ".git")
|
|
|
|
(or arg (split-string (call-process-to-string "git" "ls-files" "-z") "\0" t)))
|
2016-09-23 15:24:15 +02:00
|
|
|
(helm-grep-do-git-grep arg)
|
2017-05-26 19:43:25 +02:00
|
|
|
(helm-do-grep-ag nil)))
|
2017-05-25 12:13:37 +02:00
|
|
|
|
|
|
|
(defun helm-grep-git-all-or-ag ()
|
|
|
|
"Run `helm-grep-do-git-grep' over all git files."
|
|
|
|
(interactive)
|
|
|
|
(helm-grep-do-git-grep t))
|
2016-09-23 15:24:15 +02:00
|
|
|
|
2016-10-05 06:56:16 +02:00
|
|
|
(defun helm-mark-or-exchange-rect ()
|
2017-05-14 06:35:51 +02:00
|
|
|
"Run `helm-all-mark-rings-before-mark-point' or `rectangle-exchange-point-and-mark' if in rectangle-mark-mode."
|
2016-10-05 06:56:16 +02:00
|
|
|
(interactive)
|
|
|
|
(if rectangle-mark-mode
|
|
|
|
(rectangle-exchange-point-and-mark)
|
|
|
|
(helm-all-mark-rings)))
|
|
|
|
|
2017-09-13 22:20:04 +02:00
|
|
|
(global-set-key [remap execute-extended-command] 'helm-M-x)
|
|
|
|
(global-set-key [remap find-file] 'helm-find-files)
|
|
|
|
(global-set-key [remap occur] 'helm-occur)
|
|
|
|
(global-set-key [remap list-buffers] 'helm-mini)
|
|
|
|
;; (global-set-key [remap dabbrev-expand] 'helm-dabbrev)
|
|
|
|
(global-set-key [remap yank-pop] 'helm-show-kill-ring)
|
2017-10-24 18:12:39 +02:00
|
|
|
;;; Do not remap 'exchange-point-and-mark, Evil needs it in visual mode.
|
|
|
|
(global-set-key (kbd "C-x C-x") 'helm-mark-or-exchange-rect)
|
2017-09-13 22:20:04 +02:00
|
|
|
(global-set-key [remap apropos-command] 'helm-apropos)
|
|
|
|
(global-set-key [remap query-replace-regexp] 'helm-regexp)
|
|
|
|
(unless (boundp 'completion-in-region-function)
|
|
|
|
(define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
|
|
|
|
(define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
|
|
|
|
|
2017-06-20 20:38:59 +02:00
|
|
|
(global-set-keys
|
|
|
|
"C-x M-g" 'helm-grep-git-or-ag
|
|
|
|
"C-x M-G" 'helm-do-grep-ag)
|
2016-06-10 13:53:40 +02:00
|
|
|
|
2017-10-10 18:43:05 +02:00
|
|
|
;;; Use the M-s prefix just like `occur'.
|
2017-10-17 00:52:50 +02:00
|
|
|
(define-key prog-mode-map (kbd "M-s f") 'helm-semantic-or-imenu)
|
2017-05-28 18:39:25 +02:00
|
|
|
;;; The text-mode-map binding targets structured text modes like Markdown.
|
2017-10-17 00:52:50 +02:00
|
|
|
(define-key text-mode-map (kbd "M-s f") 'helm-semantic-or-imenu)
|
2017-06-18 20:20:37 +02:00
|
|
|
(with-eval-after-load 'org
|
2017-10-17 00:52:50 +02:00
|
|
|
(define-key org-mode-map (kbd "M-s f") 'helm-org-in-buffer-headings))
|
2017-05-25 22:58:46 +02:00
|
|
|
|
2017-06-29 21:40:58 +02:00
|
|
|
(set-face-attribute 'helm-source-header nil :inherit 'header-line :height 'unspecified :background 'unspecified :foreground 'unspecified)
|
2016-06-10 13:53:40 +02:00
|
|
|
(set-face-background 'helm-selection "#4f4f4f")
|
|
|
|
(set-face-background 'helm-visible-mark "#2f2f2f")
|
|
|
|
(set-face-foreground 'helm-visible-mark nil)
|
2016-06-10 14:18:22 +02:00
|
|
|
(set-face-foreground 'helm-match "red")
|
2016-06-12 22:50:34 +02:00
|
|
|
(set-face-attribute 'helm-buffer-file nil :background 'unspecified :foreground "white" :weight 'normal)
|
2016-06-10 13:53:40 +02:00
|
|
|
(set-face-attribute 'helm-buffer-directory nil :background 'unspecified :foreground "#1e90ff" :weight 'bold)
|
|
|
|
(set-face-attribute 'helm-ff-directory nil :background 'unspecified :foreground 'unspecified :weight 'unspecified :inherit 'helm-buffer-directory)
|
|
|
|
(set-face-attribute 'helm-ff-file nil :background 'unspecified :foreground 'unspecified :weight 'unspecified :inherit 'helm-buffer-file)
|
2017-07-27 17:32:39 +02:00
|
|
|
(set-face-foreground 'helm-grep-finish "#00AA00")
|
2016-06-10 13:53:40 +02:00
|
|
|
|
2017-06-25 13:13:24 +02:00
|
|
|
(setq helm-source-names-using-follow '("Occur" "Git-Grep" "AG" "mark-ring" "Org Headings"))
|
2016-12-11 06:18:02 +01:00
|
|
|
|
2017-06-18 15:12:32 +02:00
|
|
|
;;; From https://www.reddit.com/r/emacs/comments/5q922h/removing_dot_files_in_helmfindfiles_menu/.
|
2017-06-12 22:31:08 +02:00
|
|
|
(defun helm-skip-dots (old-func &rest args)
|
|
|
|
"Skip . and .. initially in helm-find-files. First call OLD-FUNC with ARGS."
|
|
|
|
(apply old-func args)
|
|
|
|
(let ((sel (helm-get-selection)))
|
|
|
|
(if (and (stringp sel) (string-match "/\\.$" sel))
|
|
|
|
(helm-next-line 2)))
|
|
|
|
(let ((sel (helm-get-selection))) ; if we reached .. move back
|
|
|
|
(if (and (stringp sel) (string-match "/\\.\\.$" sel))
|
|
|
|
(helm-previous-line 1))))
|
|
|
|
(advice-add #'helm-preselect :around #'helm-skip-dots)
|
|
|
|
(advice-add #'helm-ff-move-to-first-real-candidate :around #'helm-skip-dots)
|
|
|
|
|
2017-06-15 19:00:05 +02:00
|
|
|
(with-eval-after-load 'desktop
|
|
|
|
(add-to-list 'desktop-globals-to-save 'helm-ff-history))
|
2017-06-12 22:31:08 +02:00
|
|
|
|
2017-06-18 15:13:07 +02:00
|
|
|
(helm-top-poll-mode)
|
|
|
|
;;; Column indices might need some customizing. See `helm-top-command' and
|
2017-11-02 22:00:38 +01:00
|
|
|
;;; https://github.com/emacs-helm/helm/issues/1586 and
|
|
|
|
;;; https://github.com/emacs-helm/helm/issues/1909.
|
2017-06-18 15:13:07 +02:00
|
|
|
|
2017-10-11 17:18:38 +02:00
|
|
|
;;; Fallback on 'find' if 'locate' is not available.
|
|
|
|
(unless (executable-find "locate")
|
|
|
|
(setq helm-locate-recursive-dirs-command "find %s -type d -regex .*%s.*$"))
|
|
|
|
|
2017-10-29 20:59:28 +01:00
|
|
|
;;; Convenience.
|
2017-12-01 10:57:52 +01:00
|
|
|
(defun helm-toggle-visible-mark-backwards (arg)
|
|
|
|
(interactive "p")
|
|
|
|
(helm-toggle-visible-mark (- arg)))
|
2017-10-29 20:59:28 +01:00
|
|
|
(define-key helm-map (kbd "S-SPC") 'helm-toggle-visible-mark-backwards)
|
|
|
|
|
2017-06-18 18:50:31 +02:00
|
|
|
(provide 'init-helm)
|