ENH fix when-bin and friends indentation

This commit is contained in:
Nathan Dwarshuis 2019-10-04 10:51:56 -04:00
parent c6daf14c10
commit ed5b9f9a73
1 changed files with 181 additions and 181 deletions

View File

@ -135,17 +135,20 @@ event of an error or nonlocal exit."
(defmacro nd/when-os (os &rest body) (defmacro nd/when-os (os &rest body)
"Execute BODY if the operating system is OS. "Execute BODY if the operating system is OS.
OS is one of those in `system-type'." OS is one of those in `system-type'."
(declare (indent 1))
`(if (eq system-type ,os) (progn ,@body) `(if (eq system-type ,os) (progn ,@body)
(print "Skipping OS-restricted code"))) (print "Skipping OS-restricted code")))
(defmacro nd/when-not-os (os &rest body) (defmacro nd/when-not-os (os &rest body)
"Execute BODY if the operating system is not OS. "Execute BODY if the operating system is not OS.
OS is one of those in `system-type'." OS is one of those in `system-type'."
(declare (indent 1))
`(when (not (eq system-type ,os)) (progn ,@body) `(when (not (eq system-type ,os)) (progn ,@body)
(print "Skipping OS-restricted code"))) (print "Skipping OS-restricted code")))
(defmacro nd/when-bin (bin &rest body) (defmacro nd/when-bin (bin &rest body)
"Execute BODY if the program BIN exists." "Execute BODY if the program BIN exists."
(declare (indent 1))
`(if (executable-find ,bin) (progn ,@body) `(if (executable-find ,bin) (progn ,@body)
(print (format "Executable %s not found. Skipping." ,bin)))) (print (format "Executable %s not found. Skipping." ,bin))))
@ -2874,26 +2877,25 @@ make sizes human readable
*** mu4e attachments *** mu4e attachments
By default the included gnus-dired package does not understan mu4e, so override the existing =gnus-dired-mail-buffers= function to fix. This allows going to a dired buffer, marking files, and attaching them interactively to mu4e draft buffers. By default the included gnus-dired package does not understan mu4e, so override the existing =gnus-dired-mail-buffers= function to fix. This allows going to a dired buffer, marking files, and attaching them interactively to mu4e draft buffers.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(nd/when-bin (nd/when-bin "mu"
"mu" ;; from here:
;; from here: ;; https://www.djcbsoftware.nl/code/mu/mu4e/Dired.html#Dired
;; https://www.djcbsoftware.nl/code/mu/mu4e/Dired.html#Dired (require 'gnus-dired)
(require 'gnus-dired)
(eval-after-load 'gnus-dired (eval-after-load 'gnus-dired
'(defun gnus-dired-mail-buffers () '(defun gnus-dired-mail-buffers ()
"Return a list of active mu4e message buffers." "Return a list of active mu4e message buffers."
(let (buffers) (let (buffers)
(save-current-buffer (save-current-buffer
(dolist (buffer (buffer-list t)) (dolist (buffer (buffer-list t))
(set-buffer buffer) (set-buffer buffer)
(when (and (derived-mode-p 'message-mode) (when (and (derived-mode-p 'message-mode)
(null message-sent-message-via)) (null message-sent-message-via))
(push (buffer-name buffer) buffers)))) (push (buffer-name buffer) buffers))))
(nreverse buffers)))) (nreverse buffers))))
(setq gnus-dired-mail-mode 'mu4e-user-agent) (setq gnus-dired-mail-mode 'mu4e-user-agent)
(add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)) (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode))
#+END_SRC #+END_SRC
*** directory sized *** directory sized
By default dired uses =ls -whatever= to get its output. This does not have recursive directory contents by default. This nitfy package solves this. This is not on default because navigation is much slower and the du output adds very little in many situations (toggle when needed). By default dired uses =ls -whatever= to get its output. This does not have recursive directory contents by default. This nitfy package solves this. This is not on default because navigation is much slower and the du output adds very little in many situations (toggle when needed).
@ -2955,176 +2957,175 @@ Filtering is useful for obvious reasons
** mu4e ** mu4e
Since mu4e is an external program, need to check that it is installed before loading anything. Since mu4e is an external program, need to check that it is installed before loading anything.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(nd/when-bin (nd/when-bin "mu"
"mu" (require 'mu4e)
(require 'mu4e) (defun nd/make-mu4e-context (name dir addr smtp-srv sent-behavior)
(defun nd/make-mu4e-context (name dir addr smtp-srv sent-behavior) (let ((trash (format "/%s/trash" dir))
(let ((trash (format "/%s/trash" dir)) (drafts (format "/%s/drafts" dir))
(drafts (format "/%s/drafts" dir)) (sent (format "/%s/sent" dir))
(sent (format "/%s/sent" dir)) (archive (format "/%s/archive" dir))
(archive (format "/%s/archive" dir)) (inbox (format "/%s/inbox" dir))
(inbox (format "/%s/inbox" dir)) (mf (lambda (d msg)
(mf (lambda (d msg) (-some-->
(-some--> msg
msg (mu4e-message-field it :maildir)
(mu4e-message-field it :maildir) (string-prefix-p (concat "/" d) it)))))
(string-prefix-p (concat "/" d) it))))) (make-mu4e-context
(make-mu4e-context :name name
:name name :match-func (-partial mf dir) ; use lexical scope here
:match-func (-partial mf dir) ; use lexical scope here :vars `((mu4e-trash-folder . ,trash)
:vars `((mu4e-trash-folder . ,trash) (mu4e-drafts-folder . ,drafts)
(mu4e-drafts-folder . ,drafts) (mu4e-sent-folder . ,sent)
(mu4e-sent-folder . ,sent) (mu4e-refile-folder . ,archive)
(mu4e-refile-folder . ,archive) (mu4e-sent-messages-behavior . ,sent-behavior)
(mu4e-sent-messages-behavior . ,sent-behavior) (smtpmail-stream-type . starttls)
(smtpmail-stream-type . starttls) (smtpmail-smtp-server . ,smtp-srv)
(smtpmail-smtp-server . ,smtp-srv) (smtpmail-smtp-service . 587)
(smtpmail-smtp-service . 587) (smtpmail-smtp-user . ,addr)
(smtpmail-smtp-user . ,addr) (user-mail-address . ,addr)
(user-mail-address . ,addr) (mu4e-maildir-shortcuts . ((,inbox . ?i)
(mu4e-maildir-shortcuts . ((,inbox . ?i) (,sent . ?s)
(,sent . ?s) (,trash . ?t)
(,trash . ?t) (,drafts . ?d)
(,drafts . ?d) (,archive . ?a)))))))
(,archive . ?a))))))) (setq mail-user-agent 'mu4e-user-agent
(setq mail-user-agent 'mu4e-user-agent message-kill-buffer-on-exit t
message-kill-buffer-on-exit t
;; misc ;; misc
mu4e-change-filenames-when-moving t mu4e-change-filenames-when-moving t
mu4e-confirm-quit nil mu4e-confirm-quit nil
mu4e-compose-dont-reply-to-self t mu4e-compose-dont-reply-to-self t
mu4e-get-mail-command "systemctl --user start mbsync" mu4e-get-mail-command "systemctl --user start mbsync"
mu4e-use-fancy-chars nil mu4e-use-fancy-chars nil
;; directories ;; directories
mu4e-maildir "/mnt/data/Mail" mu4e-maildir "/mnt/data/Mail"
mu4e-attachment-dir "~/Downloads" mu4e-attachment-dir "~/Downloads"
;; headers ;; headers
mu4e-headers-show-target nil mu4e-headers-show-target nil
mu4e-headers-fields '((:human-date . 11) mu4e-headers-fields '((:human-date . 11)
(:flags . 5) (:flags . 5)
(:from . 22) (:from . 22)
(:thread-subject)) (:thread-subject))
mu4e-headers-date-format "%F" mu4e-headers-date-format "%F"
mu4e-headers-time-format "%R" mu4e-headers-time-format "%R"
;; view ;; view
mu4e-view-show-images t mu4e-view-show-images t
mu4e-view-show-addresses t mu4e-view-show-addresses t
mu4e-view-prefer-html t mu4e-view-prefer-html t
;; compose ;; compose
mu4e-compose-signature-auto-include nil ;; sigs are annoying by default mu4e-compose-signature-auto-include nil ;; sigs are annoying by default
mu4e-compose-signature mu4e-compose-signature
(string-join (string-join
'("Nathan Dwarshuis" '("Nathan Dwarshuis"
"" ""
"PhD Candidate - Biomedical Engineering - Krish Roy Lab" "PhD Candidate - Biomedical Engineering - Krish Roy Lab"
"Georgia Institute of Technology and Emory University" "Georgia Institute of Technology and Emory University"
"ndwarshuis3@gatech.edu") "ndwarshuis3@gatech.edu")
"\n") "\n")
;; aliases ;; aliases
mail-personal-alias-file (no-littering-expand-etc-file-name mail-personal-alias-file (no-littering-expand-etc-file-name
"mailrc") "mailrc")
;; yanking (aka citing) ;; yanking (aka citing)
message-yank-prefix "" ;; the ">" characters are annoying message-yank-prefix "" ;; the ">" characters are annoying
message-yank-cited-prefix "" message-yank-cited-prefix ""
message-yank-empty-prefix "" message-yank-empty-prefix ""
;; contexts (multiple inboxes) ;; contexts (multiple inboxes)
mu4e-context-policy 'pick-first mu4e-context-policy 'pick-first
mu4e-compose-context-policy 'ask-if-none mu4e-compose-context-policy 'ask-if-none
mu4e-user-mail-address-list '("ndwar@yavin4.ch" mu4e-user-mail-address-list '("ndwar@yavin4.ch"
"natedwarshuis@gmail.com" "natedwarshuis@gmail.com"
"ndwarshuis3@gatech.edu" "ndwarshuis3@gatech.edu"
"ndwarsh@emory.edu") "ndwarsh@emory.edu")
mu4e-contexts mu4e-contexts
(list (list
(nd/make-mu4e-context "personal" (nd/make-mu4e-context "personal"
"yavin4" "yavin4"
"ndwar@yavin4.ch" "ndwar@yavin4.ch"
"peart4prez.yavin4.ch" "peart4prez.yavin4.ch"
'sent) 'sent)
(nd/make-mu4e-context "alpha" (nd/make-mu4e-context "alpha"
"gmail" "gmail"
"natedwarshuis@gmail.com" "natedwarshuis@gmail.com"
"smtp.gmail.com" "smtp.gmail.com"
'delete) 'delete)
(nd/make-mu4e-context "gatech" (nd/make-mu4e-context "gatech"
"gatech" "gatech"
"ndwarshuis3@gatech.edu" "ndwarshuis3@gatech.edu"
"smtp.office365.com" "smtp.office365.com"
'sent) 'sent)
(nd/make-mu4e-context "emory" (nd/make-mu4e-context "emory"
"emory" "emory"
"ndwarsh@emory.edu" "ndwarsh@emory.edu"
"smtp.office365.com" "smtp.office365.com"
'sent))) 'sent)))
;; enable visual line mode and spell checking ;; enable visual line mode and spell checking
(add-hook 'mu4e-compose-mode-hook 'turn-off-auto-fill) (add-hook 'mu4e-compose-mode-hook 'turn-off-auto-fill)
(add-hook 'mu4e-compose-mode-hook 'visual-line-mode) (add-hook 'mu4e-compose-mode-hook 'visual-line-mode)
(add-hook 'mu4e-view-mode-hook 'turn-off-auto-fill) (add-hook 'mu4e-view-mode-hook 'turn-off-auto-fill)
(add-hook 'mu4e-view-mode-hook 'visual-line-mode) (add-hook 'mu4e-view-mode-hook 'visual-line-mode)
(add-hook 'mu4e-compose-mode-hook (lambda () (flyspell-mode 1))) (add-hook 'mu4e-compose-mode-hook (lambda () (flyspell-mode 1)))
;; Outlook doesn't know how to fold mu4e messages by default ;; Outlook doesn't know how to fold mu4e messages by default
;; This is enabled by using 32 underscores followed by the addressing ;; This is enabled by using 32 underscores followed by the addressing
;; info of the previou message(s). ;; info of the previou message(s).
(require 'nnheader) ; necessary for the header macros below (require 'nnheader) ; necessary for the header macros below
(defun nd/message-insert-citation-header () (defun nd/message-insert-citation-header ()
"Insert the header of the reply message." "Insert the header of the reply message."
(let* ((h message-reply-headers) (let* ((h message-reply-headers)
(sep "________________________________") (sep "________________________________")
(from (concat "From: " (mail-header-from h))) (from (concat "From: " (mail-header-from h)))
(date (concat "Sent: " (mail-header-date h))) (date (concat "Sent: " (mail-header-date h)))
(to (concat "To: " user-full-name)) (to (concat "To: " user-full-name))
(subj (concat "Subject: " (message-strip-subject-re (mail-header-subject h))))) (subj (concat "Subject: " (message-strip-subject-re (mail-header-subject h)))))
(insert (string-join `("" ,sep ,from ,date ,to ,subj "") "\n")))) (insert (string-join `("" ,sep ,from ,date ,to ,subj "") "\n"))))
(setq message-citation-line-function 'nd/message-insert-citation-header) (setq message-citation-line-function 'nd/message-insert-citation-header)
;; prevent html to text conversion from destroying links ;; prevent html to text conversion from destroying links
(setq (setq
mu4e-compose-pre-hook mu4e-compose-pre-hook
(lambda () (lambda ()
(let* ((msg mu4e-compose-parent-message) (let* ((msg mu4e-compose-parent-message)
(html (and msg (plist-get msg :body-html))) (html (and msg (plist-get msg :body-html)))
;; oops, mu4e screwed up ;; oops, mu4e screwed up
(mu4e-html2text-command (mu4e-html2text-command
(if (executable-find "pandoc") (if (executable-find "pandoc")
"pandoc -f html -t plain --reference-links" "pandoc -f html -t plain --reference-links"
'mu4e-shr2text))) 'mu4e-shr2text)))
(when (and html mu4e-view-prefer-html (member compose-type '(reply forward))) (when (and html mu4e-view-prefer-html (member compose-type '(reply forward)))
;; hackity hack, since the normal mu4e-message-body-text function ;; hackity hack, since the normal mu4e-message-body-text function
;; does not render the desired html, do it here and force the ;; does not render the desired html, do it here and force the
;; aforementioned function to only look at text by removing ;; aforementioned function to only look at text by removing
;; the html ;; the html
(plist-put msg :body-txt (mu4e~html2text-shell msg mu4e-html2text-command)) (plist-put msg :body-txt (mu4e~html2text-shell msg mu4e-html2text-command))
(plist-put msg :body-html nil))))) (plist-put msg :body-html nil)))))
(require 'smtpmail) (require 'smtpmail)
;; (require 'smtpmail-async) ;; (require 'smtpmail-async)
;; (require 'secrets) ;; (require 'secrets)
;; (setq secrets-enabled t) ;; (setq secrets-enabled t)
;; (add-to-list 'auth-sources "secrets:default") ;; (add-to-list 'auth-sources "secrets:default")
(setq send-mail-function 'smtpmail-send-it (setq send-mail-function 'smtpmail-send-it
message-send-mail-function 'smtpmail-send-it) message-send-mail-function 'smtpmail-send-it)
(add-to-list 'auth-sources (no-littering-expand-etc-file-name "authinfo_mu4e.gpg")) (add-to-list 'auth-sources (no-littering-expand-etc-file-name "authinfo_mu4e.gpg"))
(use-package org-mu4e (use-package org-mu4e
:after (org mu4e) :after (org mu4e)
:config :config
(setq (setq
;; for using mu4e in org-capture templates ;; for using mu4e in org-capture templates
org-mu4e-link-query-in-headers-mode nil org-mu4e-link-query-in-headers-mode nil
;; for composing rich-text emails using org mode ;; for composing rich-text emails using org mode
org-mu4e-convert-to-html t))) org-mu4e-convert-to-html t)))
#+END_SRC #+END_SRC
** shell ** shell
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -3696,10 +3697,9 @@ These are for mode-specific bindings that can/should be outside of the evil maps
;; (attnum (or attnum (mu4e~view-get-attach-num "Attachment to open" msg)))) ;; (attnum (or attnum (mu4e~view-get-attach-num "Attachment to open" msg))))
;; (mu4e-view-open-attachment-emacs msg attnum))) ;; (mu4e-view-open-attachment-emacs msg attnum)))
(nd/when-bin (nd/when-bin "mu"
"mu" (define-key mu4e-headers-mode-map (kbd "C-c C-l") 'org-store-link)
(define-key mu4e-headers-mode-map (kbd "C-c C-l") 'org-store-link) (define-key mu4e-view-mode-map (kbd "C-c C-l") 'org-store-link))
(define-key mu4e-view-mode-map (kbd "C-c C-l") 'org-store-link))
#+END_SRC #+END_SRC
*** dired *** dired
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp