diff --git a/init.el b/init.el index 800ccd3..0f76dee 100644 --- a/init.el +++ b/init.el @@ -1239,22 +1239,7 @@ accordingly." (funcall orig-fun host port user (password-read (format "Password for %s@%s: " user database)) - database)))) - - (define-advice org-babel-execute:sql (:around - (orig-fun body params) - retrieve-password-by-function) - "Allow to set :dbpassword by an ID of an Org items having the PASSWORD property." - (let* ((dbpassword-id (cdr (assq :dbpassword-by-id params))) - (params params)) - (when dbpassword-id - (setq params (cons (cons :dbpassword - (let* ((pom (or (org-id-find dbpassword-id 'marker) - (user-error "Cannot find ID %s" dbpassword-id)))) - (or (org-entry-get pom "PASSWORD") - (user-error "No PASSWORD property at ID %s" dbpassword-id)))) - params))) - (funcall orig-fun body params))))) + database)))))) ;; Exporting diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 940cbf3..7de03bc 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -1164,10 +1164,14 @@ cache if that's in use." (when (derived-mode-p 'org-agenda-mode) (org-agenda-redo))) -(defun org-password-manager-get-password-by-id (id) +(defun org-password-manager-get-password-by-id (id &optional return-as-value) "Retrieve password from Org item identified by ID. -The password is assumed to be stored at the PASSWORD property." +The password is assumed to be stored at the PASSWORD property. +When RETURN-AS-VALUE is nil, the password is copied to the +clipboard as with `org-password-manager-get-password', which see. +Otherwise, the password is returned as value from this function +and can be used for further processing." (require 'org-password-manager) (let ((pom (org-id-find id 'marker))) @@ -1179,13 +1183,15 @@ The password is assumed to be stored at the PASSWORD property." (when (null pw) (user-error "PASSWORD property not set for “%s”" heading)) - (funcall interprogram-cut-function pw) - (run-at-time org-password-manager-default-password-wait-time - nil - (lambda () (funcall interprogram-cut-function ""))) - (message "Password for “%s” securly copied to system clipboard; will be overwritten in %s." - heading - org-password-manager-default-password-wait-time)))) + (if return-as-value + pw + (funcall interprogram-cut-function pw) + (run-at-time org-password-manager-default-password-wait-time + nil + (lambda () (funcall interprogram-cut-function ""))) + (message "Password for “%s” securly copied to system clipboard; will be overwritten in %s." + heading + org-password-manager-default-password-wait-time))))) (defhydra hydra-org-jump (:color blue) ;; Quote %, as otherwise they would be misinterpreted as format characters