Emacs: Replace helm-defswitcher by helm-selector.

master
Pierre Neidhardt 2020-07-06 19:02:45 +02:00
parent 121bc910f6
commit b10fe7ed09
10 changed files with 32 additions and 221 deletions

View File

@ -113,11 +113,9 @@
(when (require 'evil nil t) (require 'init-evil))
(with-eval-after-load 'eshell (require 'init-eshell))
(autoload 'helm-eshell-switch "eshell")
(with-eval-after-load 'shell (require 'init-shell))
(with-eval-after-load 'eww (require 'init-eww))
(autoload 'helm-eww-switch "eww")
(when (require 'expand-region nil t)
(global-set-key (kbd "C-=") 'er/expand-region))
@ -174,15 +172,8 @@
(when (require 'info-colors nil t)
(add-hook 'Info-selection-hook 'info-colors-fontify-node))
(with-eval-after-load 'helm
(helm-defswitcher
"Info"
(lambda (b)
(with-current-buffer b
(derived-mode-p 'Info-mode)))
(lambda (&optional candidate)
(info nil (when candidate (format "*info*<%s>" candidate)))))
(global-set-key (kbd "C-h i") 'helm-info-switch))
(when (require 'helm-selector nil :noerror)
(global-set-key (kbd "C-h i") 'helm-selector-info))
(add-hook 'js-mode-hook (lambda () (defvaralias 'js-indent-level 'tab-width)))
@ -190,6 +181,7 @@
(with-eval-after-load 'scheme (require 'init-scheme))
(with-eval-after-load 'racket-mode (require 'init-racket))
(with-eval-after-load 'clojure-mode (require 'init-clojure))
(setq geiser-repl-history-filename (expand-file-name "geiser_history" user-emacs-directory))
;; Emacs Lisp
(add-hook 'emacs-lisp-mode-hook 'ambrevar/turn-on-complete-filename)
@ -248,7 +240,6 @@
;; (autoload 'helm-mu4e-switch "mu4e")
(with-eval-after-load 'notmuch (require 'init-notmuch))
(autoload 'helm-notmuch-switch "notmuch")
(with-eval-after-load 'make-mode (require 'init-makefile))
@ -268,10 +259,8 @@
(with-eval-after-load 'mediawiki (require 'init-mediawiki))
(with-eval-after-load 'elfeed (require 'init-elfeed))
(autoload 'helm-elfeed-switch "elfeed")
(with-eval-after-load 'org (require 'init-org))
(autoload 'helm-org-switch "org")
;;; pdf-tools requires poppler built with cairo support.
;;; We cannot defer loading as `pdf-tools-install' is required for PDF

View File

@ -87,16 +87,6 @@ visit otherwise."
(funcall elfeed-show-entry-switch buff)))
(advice-add 'elfeed-show-entry :override 'ambrevar/elfeed-show-entry)
(when (require 'patch-helm nil 'noerror)
(helm-defswitcher
"elfeed"
(lambda (b)
(with-current-buffer b
(or
(derived-mode-p 'elfeed-search-mode)
(derived-mode-p 'elfeed-show-mode))))
elfeed))
(defun ambrevar/elfeed-setup ()
(add-hook 'window-configuration-change-hook 'elfeed-search-update--force nil t))
;; This is too slow on big buffers.

View File

@ -214,34 +214,6 @@ This should be faster then `seq-uniq'."
;; (setq epa-file-encrypt-to "mail@ambrevar.xyz"))
;; (add-hook 'eshell-mode-hook 'ambrevar/fix-local-epa-file-encrypt-to)
;;; Spawning
(require 'init-shell); For `helm-ff-preferred-shell-mode'.
(when (require 'patch-helm nil 'noerror)
(helm-defswitcher
"Eshell"
(lambda (b)
(with-current-buffer b
(or
(derived-mode-p 'eshell-mode)
(derived-mode-p 'shell-mode))))
(lambda (&optional name)
(if (eq helm-ff-preferred-shell-mode 'eshell-mode)
(eshell 'new)
(shell (generate-new-buffer (generate-new-buffer-name "*shell*"))))
(when name
(rename-buffer (format "*%sshell<%s>*"
(if (eq helm-ff-preferred-shell-mode 'eshell-mode) "e" "")
name)
'unique)))
nil
(helm-build-dummy-source
"Create shell buffer"
:action `(("Create shell buffer" .
(lambda (candidate)
(let ((new-buffer (save-window-excursion (shell (format "*shell<%s>*" candidate))
(current-buffer))))
(switch-to-buffer new-buffer))))))))
;;; Auto-suggestion
(when (require 'esh-autosuggest nil t)
(setq esh-autosuggest-delay 0.75)

View File

@ -68,20 +68,6 @@ If BUFFERS is not specified, then reload all buffers."
(when (derived-mode-p 'eww-mode)
(eww-reload)))))
(when (require 'patch-helm nil 'noerror)
(helm-defswitcher
"eww"
(lambda (b)
(with-current-buffer b
(derived-mode-p 'eww-mode)))
(lambda (&optional _)
(interactive)
(if (thing-at-point-url-at-point)
;; This only works fine if no EWW buffer is up.
(call-interactively 'eww)
(helm-eww)))
helm-eww))
(defun ambrevar/eww (url)
"Fetch URL and render the page.
If the input doesn't look like an URL or a domain name, the

View File

@ -77,14 +77,26 @@
(exwm-input-set-key (kbd "C-6") #'evil-switch-to-windows-last-buffer))
;;; Emacs mode shortcuts.
(if (not (fboundp 'helm-org-switch))
(exwm-input-set-key (kbd "s-t") (lambda () (interactive) (find-file (car org-agenda-files))))
(exwm-input-set-key (kbd "s-t") #'helm-org-switch)
(exwm-input-set-key (kbd "s-T") #'helm-org-switch-other-window))
(if (not (fboundp 'helm-eshell-switch))
(exwm-input-set-key (kbd "s-<return>") #'eshell)
(exwm-input-set-key (kbd "s-<return>") #'helm-eshell-switch)
(exwm-input-set-key (kbd "S-s-<return>") #'helm-eshell-switch-other-window))
(if (not (require 'helm-selector nil :noerror))
(progn
(exwm-input-set-key (kbd "s-t") (lambda ()
(interactive)
(find-file (car org-agenda-files))))
(exwm-input-set-key (kbd "s-<return>") #'eshell)
(exwm-input-set-key (kbd "s-m") #'notmuch-hello)
(exwm-input-set-key (kbd "s-n") #'elfeed)
(exwm-input-set-key (kbd "s-e") #'eww))
(exwm-input-set-key (kbd "s-t") 'helm-selector-org)
(exwm-input-set-key (kbd "s-T") 'helm-selector-org-other-window)
(exwm-input-set-key (kbd "s-<return>") 'helm-selector-shell)
(exwm-input-set-key (kbd "S-s-<return>") 'helm-selector-shell-other-window)
(exwm-input-set-key (kbd "s-m") #'helm-selector-notmuch)
(exwm-input-set-key (kbd "s-M") #'helm-selector-notmuch-other-window)
(exwm-input-set-key (kbd "s-n") #'helm-selector-elfeed)
(exwm-input-set-key (kbd "s-N") #'helm-selector-elfeed-other-window) ; "n" for "news"
(exwm-input-set-key (kbd "s-e") #'helm-selector-eww)
(exwm-input-set-key (kbd "s-E") #'helm-selector-eww-other-window))
(when (fboundp 'magit-status)
(exwm-input-set-key (kbd "s-v") #'magit-status))
(when (fboundp 'emms-all)
@ -93,24 +105,6 @@
(if (fboundp 'helm-emms)
(exwm-input-set-key (kbd "s-A") #'helm-emms)
(exwm-input-set-key (kbd "s-A") #'emms)))
;; (when (or (fboundp 'mu4e)
;; (delq nil (mapcar (lambda (path) (string-match "/mu4e/\\|/mu4e$" path)) load-path)))
;; (if (not (fboundp 'helm-mu4e-switch))
;; (exwm-input-set-key (kbd "s-m") #'ambrevar/mu4e-headers)
;; (exwm-input-set-key (kbd "s-m") #'helm-mu4e-switch)
;; (exwm-input-set-key (kbd "s-M") #'helm-mu4e-switch-other-window)))
(if (not (fboundp 'helm-notmuch-switch))
(exwm-input-set-key (kbd "s-m") #'notmuch-hello)
(exwm-input-set-key (kbd "s-m") #'helm-notmuch-switch)
(exwm-input-set-key (kbd "s-M") #'helm-notmuch-switch-other-window))
(if (not (fboundp 'helm-elfeed-switch))
(exwm-input-set-key (kbd "s-n") #'elfeed)
(exwm-input-set-key (kbd "s-n") #'helm-elfeed-switch)
(exwm-input-set-key (kbd "s-N") #'helm-elfeed-switch-other-window)) ; "n" for "news"
(if (not (fboundp 'helm-eww-switch))
(exwm-input-set-key (kbd "s-e") #'eww)
(exwm-input-set-key (kbd "s-e") #'helm-eww-switch)
(exwm-input-set-key (kbd "s-E") #'helm-eww-switch-other-window))
(when (fboundp 'helm-pass)
(exwm-input-set-key (kbd "s-p") #'helm-pass))
@ -120,22 +114,25 @@
(defun ambrevar/repl-switcher ()
"Switch between Geiser and SLIME REPLs."
(interactive)
;; TODO: Apparently, S-s-<backspace> is not recognized.
(pcase
(completing-read "Lisp: " '(cider geiser slime sly racket))
("cider"
(exwm-input-set-key (kbd "s-<backspace>") #'ambrevar/cider-switch-to-repl))
(exwm-input-set-key (kbd "s-<backspace>") 'helm-selector-cider)
(exwm-input-set-key (kbd "M-s-<backspace>") 'helm-selector-cider-other-window))
("geiser"
(autoload 'helm-geiser-repl-switch "init-scheme")
(exwm-input-set-key (kbd "s-<backspace>") #'helm-geiser-repl-switch)
(exwm-input-set-key (kbd "S-s-<backspace>") #'helm-geiser-repl-switch-other-window))
(exwm-input-set-key (kbd "s-<backspace>") 'helm-selector-geiser)
(exwm-input-set-key (kbd "M-s-<backspace>") 'helm-selector-geiser-other-window))
("slime"
(exwm-input-set-key (kbd "s-<backspace>") #'ambrevar/slime-switch-to-repl))
(exwm-input-set-key (kbd "s-<backspace>") 'helm-selector-slime)
(exwm-input-set-key (kbd "M-s-<backspace>") 'helm-selector-slime-other-window))
("sly"
(exwm-input-set-key (kbd "s-<backspace>") #'ambrevar/sly-switch-to-repl))
(exwm-input-set-key (kbd "s-<backspace>") 'helm-selector-sly)
(exwm-input-set-key (kbd "<M-s-backspace>") 'helm-selector-sly-other-window))
("racket"
(exwm-input-set-key (kbd "s-<backspace>") #'racket-repl))))
(exwm-input-set-key (kbd "s-C-<backspace>") #'ambrevar/repl-switcher)
(autoload #'ambrevar/cider-switch-to-repl "init-clojure")
;;; External application shortcuts.
(defun ambrevar/exwm-start (command)

View File

@ -121,20 +121,6 @@ If MSG is nil, use message at point."
(interactive)
(kill-new (mu4e-message-field (or msg (mu4e-message-at-point)) :message-id)))
(when (require 'patch-helm nil 'noerror)
(helm-defswitcher
"mu4e"
(lambda (b)
(with-current-buffer b
(or
(derived-mode-p 'mu4e-main-mode)
(derived-mode-p 'mu4e-headers-mode)
(derived-mode-p 'mu4e-view-mode)
(derived-mode-p 'mu4e-compose-mode)
(when (require 'mu4e-conversation nil 'noerror)
(mu4e-conversation--buffer-p b)))))
ambrevar/mu4e-headers))
(load "~/personal/mail/mu4e.el" t)
(provide 'init-mu4e)

View File

@ -30,12 +30,6 @@
(message-remove-header "Fcc")
(notmuch-fcc-header-setup))
(when (require 'patch-helm nil 'noerror)
(helm-defswitcher
"notmuch"
#'notmuch-interesting-buffer
notmuch-hello))
(when (require 'helm-notmuch nil t)
(setq helm-notmuch-match-incomplete-words t)
(dolist (map (list notmuch-search-mode-map

View File

@ -30,18 +30,6 @@
(add-to-list 'org-agenda-files "~/personal/todo/todo.org.gpg")
(load "~/personal/todo/agenda-list.el" 'noerror)
(when (require 'patch-helm nil 'noerror)
(helm-defswitcher
"Org"
(lambda (b)
(when (buffer-file-name b)
(member (file-truename (buffer-file-name b)) (mapcar #'file-truename org-agenda-files))))
(lambda () (find-file (car org-agenda-files)))
nil
(helm-make-source "Org agenda files" 'helm-source-ffiles
;; Unclear why, but if we don't copy the list, the last element gets removed.
:candidates (lambda () (copy-list org-agenda-files)))))
;;; Set PDF association in Org-mode (original is 'default).
(setcdr (assoc "\\.pdf\\'" org-file-apps) 'emacs)

View File

@ -18,19 +18,6 @@
(add-hook 'scheme-mode-hook 'al/scheme-fix-docstring-font-lock)))
(when (require 'geiser-impl nil 'noerror)
(helm-defswitcher
"Geiser-REPL"
(lambda (b)
(with-current-buffer b
(derived-mode-p 'geiser-repl-mode)))
(lambda (&optional candidate)
(defun ambrevar/geiser-repl-buffer-name (impl)
(format "* %s%s *" (geiser-repl--repl-name impl)
(if candidate (format "-%s" candidate) "")))
(advice-add 'geiser-repl-buffer-name :override 'ambrevar/geiser-repl-buffer-name)
(call-interactively 'run-geiser)
(advice-remove 'geiser-repl-buffer-name 'ambrevar/geiser-repl-buffer-name)))
;; (setq geiser-repl-skip-version-check-p t
;; geiser-mode-start-repl-p t)
(setq geiser-active-implementations (delq 'chicken geiser-active-implementations)

View File

@ -1,78 +0,0 @@
;; TODO: Since Helm 3.1, we can pop up buffers in other window/frame.
(defun ambrevar/helm-source-buffer-not-found (&optional mode new-fn)
"See `helm-source-buffer-not-found'."
(helm-build-dummy-source
"Create buffer"
:action `(("Create buffer (C-u choose mode)" .
(lambda (candidate)
(if (not ,new-fn)
(let ((mjm (or (and helm-current-prefix-arg
(intern-soft (helm-comp-read
"Major-mode: "
helm-buffers-favorite-modes)))
,mode
(cl-loop for (r . m) in auto-mode-alist
when (string-match r candidate)
return m)))
(buffer (get-buffer-create candidate)))
(if mjm
(with-current-buffer buffer (funcall mjm))
(set-buffer-major-mode buffer))
(switch-to-buffer buffer))
(let ((new-buffer (save-window-excursion (funcall ',new-fn candidate)
(current-buffer))))
(switch-to-buffer new-buffer))))))))
(defmacro helm-deflister (name predicate new-fn &optional extra-sources)
(let ((buffer-source-name (format "%s buffers" name)))
(add-to-list 'helm-source-names-using-follow buffer-source-name)
`(defun ,(intern (format "helm-%s-buffers" (downcase name))) ()
(interactive)
(helm
:sources
(list (helm-make-source ,(format "%s buffers" name) 'helm-source-buffers
:buffer-list (lambda ()
(cl-loop for b in (buffer-list)
when (funcall ,predicate b)
collect (buffer-name b))))
,@(let ((mode (intern (format "%s-mode" (downcase name)))))
(unless (fboundp mode)
;; For cased mode names like `Info-mode'.
(setq mode (intern (format "%s-mode" name))))
(when (fboundp mode)
`((ambrevar/helm-source-buffer-not-found
',mode
,new-fn))))
,@extra-sources)
:buffer ,(format "*helm-%s-buffers*" name)))))
(defmacro helm-defswitcher (name predicate new-fn &optional helm-lister &rest extra-sources)
"Create an interactive buffer switcher for NAME.
When current buffer is not of NAME, switch to last NAME session if any.
Otherwise create a new one and switch to it.
If current buffer is of NAME, show the buffer list."
(let ((switch (intern (format "helm-%s-switch" (downcase name)))))
`(progn
(helm-deflister ,name ,predicate ,new-fn ,extra-sources)
(defun ,switch (&optional menu other-window)
(interactive "P")
(if (or menu (funcall ,predicate (current-buffer)))
;; TODO: Funcall the return value of helm-deflister.
(funcall ',(or helm-lister
(intern (format "helm-%s-buffers" (downcase name)))))
(let ((last (cl-loop for buffer in (buffer-list)
when (funcall ,predicate buffer)
return buffer)))
(if last
(if (get-buffer-window last)
(select-window (get-buffer-window last))
(funcall (if other-window 'switch-to-buffer-other-window 'switch-to-buffer) last))
;; First buffer:
(let ((first-buffer (save-window-excursion (funcall #',new-fn) (current-buffer))))
(funcall (if other-window 'switch-to-buffer-other-window 'switch-to-buffer)
first-buffer))))))
(defun ,(intern (format "helm-%s-switch-other-window" (downcase name))) (&optional menu)
(interactive "P")
(funcall ',switch menu 'other-window)))))
(provide 'patch-helm)