Replace some one-time advices with define-advice

From my point of view, this makes it clearer that the functions thus defined are
not meant to be used anywhere else.

Some one-time `advice-add` calls are still there, though, mostly because the
associated functions would be too long to inline them directly into their
present locations.
This commit is contained in:
Daniel - 2022-12-20 14:21:48 +01:00
parent a54ade74a4
commit 1eee33ea5d
Signed by: dbo
GPG Key ID: 784AA8DF0CCDF625
1 changed files with 19 additions and 25 deletions

44
init.el
View File

@ -1361,23 +1361,21 @@ point to the beginning of buffer first."
(use-package ob-sql (use-package ob-sql
:config (progn :config (progn
(defun db/ob-sql-oracle-ask-for-password (orig-fun (define-advice org-babel-sql-dbstring-oracle (:around
host port user password database) (orig-fun host port user password database)
ask-for-password)
"Ask for PASSWORD if not given, and call ORIG-FUN with arguments afterwards." "Ask for PASSWORD if not given, and call ORIG-FUN with arguments afterwards."
(cond (cond
((not (or (and user database host port) ((not (or (and user database host port)
(and user database))) (and user database)))
(user-error "Insufficient login credentials given, aborting")) (user-error "Insufficient login credentials given, aborting"))
(password (password
(funcall orig-fun host port user password database)) (funcall orig-fun host port user password database))
(t (t
(funcall orig-fun (funcall orig-fun
host port user host port user
(password-read (format "Password for %s@%s: " user database)) (password-read (format "Password for %s@%s: " user database))
database)))) database))))))
(advice-add #'org-babel-sql-dbstring-oracle
:around #'db/ob-sql-oracle-ask-for-password)))
;; Exporting ;; Exporting
@ -1788,16 +1786,15 @@ point to the beginning of buffer first."
;; Move to end of message buffer before attaching a file ;; Move to end of message buffer before attaching a file
;; http://mbork.pl/2015-11-28_Fixing_mml-attach-file_using_advice ;; http://mbork.pl/2015-11-28_Fixing_mml-attach-file_using_advice
(defun db/mml-attach-file--go-to-eob (orig-fun &rest args) (define-advice mml-attach-file (:around
(orig-fun &rest args)
go-to-eob)
"Go to the end of buffer before attaching files." "Go to the end of buffer before attaching files."
(save-excursion (save-excursion
(save-restriction (save-restriction
(widen) (widen)
(goto-char (point-max)) (goto-char (point-max))
(apply orig-fun args)))) (apply orig-fun args))))))
(advice-add 'mml-attach-file
:around #'db/mml-attach-file--go-to-eob)))
(use-package mm-encode (use-package mm-encode
:init (setq mm-encrypt-option nil :init (setq mm-encrypt-option nil
@ -1827,14 +1824,11 @@ point to the beginning of buffer first."
;; A previous version of this worked, but the following has not been ;; A previous version of this worked, but the following has not been
;; tested with Outlook proper. ;; tested with Outlook proper.
(defun db/smime-add-crlf-when-pkcs7 (cont) (define-advice mml-smime-epg-sign (:after (cont) add-crlf-when-pkcs7)
"If CONT signifies encryption with smime, replace all \n with \r\n." "If CONT signifies encryption with smime, replace all \n with \r\n."
(when (and (eq (car cont) 'part) (when (and (eq (car cont) 'part)
(string= "smime" (or (cdr (assq 'encrypt cont)) ""))) (string= "smime" (or (cdr (assq 'encrypt cont)) "")))
(db/convert-lf-to-crlf-in-buffer))) (db/convert-lf-to-crlf-in-buffer)))))
(advice-add 'mml-smime-epg-sign
:after #'db/smime-add-crlf-when-pkcs7)))
;; Archiving ;; Archiving