Emacs: Move Eshell and mu4e binding defuns to their init

Use autoloads.
Fix some lazy-loading.
master
Pierre Neidhardt 2017-07-26 23:08:58 +01:00
parent 66c4d177cc
commit 08354036fd
7 changed files with 32 additions and 28 deletions

View File

@ -53,9 +53,9 @@
;;; Asymptote
(add-to-list 'load-path "/usr/share/asymptote")
(autoload 'asy-mode "asy-mode.el" "Asymptote major mode." t)
(autoload 'lasy-mode "asy-mode.el" "Hybrid Asymptote/Latex major mode." t)
(autoload 'asy-insinuate-latex "asy-mode.el" "Asymptote insinuate LaTeX." t)
(autoload 'asy-mode "asy-mode" "Asymptote major mode." t)
(autoload 'lasy-mode "asy-mode" "Hybrid Asymptote/Latex major mode." t)
(autoload 'asy-insinuate-latex "asy-mode" "Asymptote insinuate LaTeX." t)
(add-to-list 'auto-mode-alist '("\\.asy$" . asy-mode))
;;; BBCode
@ -139,6 +139,7 @@
;;; Extend completion.
(nconc package-selected-packages '(pcomplete-extension))
(with-eval-after-load 'eshell (require 'init-eshell))
(autoload 'eshell-or-new-session "eshell")
;;; Esup
(nconc package-selected-packages '(esup))
@ -200,6 +201,7 @@
(when (fboundp 'mu4e)
(nconc package-selected-packages '(helm-mu mu4e-maildirs-extension mu4e-alert)))
(with-eval-after-load 'mu4e (require 'init-mu4e))
(autoload 'mu4e-headers-unread "mu4e")
;;; Makefile
(with-eval-after-load 'make-mode (require 'init-makefile))
@ -245,11 +247,13 @@
;;; Org-mode
(with-eval-after-load 'org (require 'init-org))
(autoload 'org-find-first-agenda "org")
;;; PDF
;;; pdf-tools requires poppler built with cairo support.
(nconc package-selected-packages '(pdf-tools))
(when (require 'pdf-tools nil t)
;; TODO: The reader should be compiler only when a frame is available.
(pdf-tools-install))
;;; Perl

View File

@ -95,6 +95,16 @@
(not (or (string= "" str)
(string-prefix-p " " str)))))
(defun eshell-or-new-session (&optional arg)
"Create an interactive Eshell buffer.
If there is already an Eshell session active, switch to it.
If current buffer is already an Eshell buffer, create a new one and switch to it.
See `eshell' for the numeric prefix ARG."
(interactive "P")
(if (eq major-mode 'eshell-mode)
(eshell (or arg t))
(eshell arg)))
;;; REVIEW: Emacs' standard functions fail when output has empty lines.
;;; This implementation is more reliable.
;;; Reported at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27405.

View File

@ -33,7 +33,8 @@
"G" 'helm-grep-git-all-or-ag
"r" 'helm-resume))
(when (require 'evil-mu4e nil t)
(when (fboundp 'mu4e)
(require 'evil-mu4e nil t)
(evil-leader/set-key "m" 'mu4e-headers-unread))
(provide 'init-evil-leader)

View File

@ -41,22 +41,6 @@
(evil-global-set-key 'normal "gc" 'evil-commentary)
(evil-global-set-key 'normal "gy" 'evil-commentary-yank))
(defun eshell-or-new-session (&optional arg)
"Create an interactive Eshell buffer.
If there is already an Eshell session active, switch to it.
If current buffer is already an Eshell buffer, create a new one and switch to it.
See `eshell' for the numeric prefix ARG."
(interactive "P")
(if (eq major-mode 'eshell-mode)
(eshell (or arg t))
(eshell arg)))
(defun org-find-first-agenda ()
(interactive)
(when (not (boundp 'org-agenda-files))
(require 'org))
(find-file (car org-agenda-files)))
;;; Term mode should be in emacs state. It confuses 'vi' otherwise.
;;; Upstream will not change this:
;;; https://github.com/emacs-evil/evil/issues/854#issuecomment-309085267
@ -155,9 +139,9 @@ See `eshell' for the numeric prefix ARG."
;;; since the mode-maps are defconst'd.
(with-eval-after-load 'emms-browser (require 'init-evil-emms))
(when (require 'evil-mu4e nil t)
(evil-set-initial-state 'mu4e-compose-mode 'insert)
(defun mu4e-headers-unread () (interactive) (mu4e-headers-search "flag:unread AND NOT flag:trashed")))
(with-eval-after-load 'mu4e
(when (require 'evil-mu4e nil t)
(evil-set-initial-state 'mu4e-compose-mode 'insert)))
(with-eval-after-load 'init-helm (require 'init-evil-helm))

View File

@ -71,16 +71,14 @@
(exwm-input-set-key (kbd "C-6") #'evil-switch-to-windows-last-buffer))
;;; Emacs mode shortcuts.
;; TODO: Move `org-find-first-agenda' to init-org.
(exwm-input-set-key (kbd "s-t") #'org-find-first-agenda)
;; TODO: Move `eshell-or-new-session' to init-eshell.
(exwm-input-set-key (kbd "s-<return>") #'eshell-or-new-session)
(when (require 'magit nil t)
(when (fboundp 'magit-status)
(exwm-input-set-key (kbd "s-v") #'magit-status))
(when (require 'emms nil t)
(when (fboundp 'emms)
(exwm-input-set-key (kbd "s-a") #'emms-smart-browse)
(exwm-input-set-key (kbd "s-A") #'emms))
(when (require 'mu4e nil t)
(when (fboundp 'mu4e)
(exwm-input-set-key (kbd "s-m") #'mu4e-headers-unread))
;;; External application shortcuts.

View File

@ -10,6 +10,10 @@
(when (require 'mu4e-alert nil t)
(mu4e-alert-enable-mode-line-display))
(defun mu4e-headers-unread ()
(interactive)
(mu4e-headers-search "flag:unread AND NOT flag:trashed"))
(setq
;; Where to save attachments
mu4e-attachment-dir "~/temp"

View File

@ -17,6 +17,9 @@
;;; Agendas.
(add-to-list 'org-agenda-files "~/personal/todo/todo.org")
(defun org-find-first-agenda ()
(interactive)
(find-file (car org-agenda-files)))
;;; Set PDF association in Org-mode (original is 'default).
(setcdr (assoc "\\.pdf\\'" org-file-apps) 'emacs)