From 269ec27a2160306d4cbb9b2c6caeb02371034cb3 Mon Sep 17 00:00:00 2001 From: swapn Date: Fri, 3 Mar 2023 16:45:34 -0500 Subject: [PATCH 1/5] Fix for #27 (https://github.com/charlesroelli/org-board/issues/27) --- org-board.el | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/org-board.el b/org-board.el index dc3c6b3..bcdfaff 100644 --- a/org-board.el +++ b/org-board.el @@ -691,33 +691,39 @@ added as a link in the `ARCHIVED_AT' property." (interactive) (org-board-expand-regexp-alist) - (let* ((attach-directory (org-attach-dir t)) - (urls (org-entry-get-multivalued-property (point) "URL")) - (options - (org-board-options-handler - (org-entry-get-multivalued-property (point) "WGET_OPTIONS"))) - (timestamp (org-board-make-timestamp)) - (output-directory (concat (file-name-as-directory attach-directory) - (file-name-as-directory timestamp))) - (org-id-token (org-id-get)) - (link-to-output (if (not org-board-make-relative) - (concat "[[file:" output-directory "][" - timestamp "]]") - (concat "[[file:" (file-relative-name output-directory)"][" timestamp "]]"))) - (wget-process (org-board-wget-call org-board-wget-program - output-directory - options - urls))) - (process-put wget-process 'org-entry - (org-display-outline-path nil t "/" t)) - (process-put wget-process 'wget-output-directory - output-directory) - (process-put wget-process 'org-id - org-id-token) - (process-put wget-process 'urls - (org-board-copy-list urls)) - (org-entry-add-to-multivalued-property (point) "ARCHIVED_AT" - link-to-output))) + (save-mark-and-excursion + (save-window-excursion + (let* ((attach-directory (org-attach-dir t)) + (urls (org-entry-get-multivalued-property (point) "URL")) + (options + (org-board-options-handler + (org-entry-get-multivalued-property (point) "WGET_OPTIONS"))) + (timestamp (org-board-make-timestamp)) + (output-directory (concat (file-name-as-directory attach-directory) + (file-name-as-directory timestamp))) + (org-id-token (org-id-get)) + (link-to-output (if (not org-board-make-relative) + (concat "[[file:" output-directory "][" + timestamp "]]") + (concat "[[file:" (file-relative-name output-directory)"][" timestamp "]]"))) + (wget-process (org-board-wget-call org-board-wget-program + output-directory + options + urls))) + + (org-id-goto org-id-token) + (process-put wget-process 'org-entry + (org-display-outline-path nil t "/" t)) + (process-put wget-process 'wget-output-directory + output-directory) + (process-put wget-process 'org-id + org-id-token) + (process-put wget-process 'urls + (org-board-copy-list urls)) + + (org-id-goto org-id-token) + (org-entry-add-to-multivalued-property (point) "ARCHIVED_AT" + link-to-output))))) ;;;###autoload (defun org-board-archive-dry-run () From ea9666167a59962abdefa68189c4ea7ae980dc78 Mon Sep 17 00:00:00 2001 From: swapn Date: Fri, 3 Mar 2023 18:22:48 -0500 Subject: [PATCH 2/5] Allow user-defined browser functions. --- org-board.el | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/org-board.el b/org-board.el index bcdfaff..84559ef 100644 --- a/org-board.el +++ b/org-board.el @@ -860,24 +860,37 @@ non-nil." ;; or no argument and `eww' for `org-board-default-browser', try ;; to open the file in `eww' and return 0 (success), and if an ;; error occurs, throw it back to the user. - (if (or (and arg (eq org-board-default-browser 'system)) - (and (not arg) (eq org-board-default-browser 'eww))) - (condition-case nil - (progn - (eww-open-file filename-string) - 0) - (error 1)) + (cond + ((or (and arg (eq org-board-default-browser 'system)) + (and (not arg) (eq org-board-default-browser 'eww))) + (condition-case nil + (progn + (eww-open-file filename-string) + 0) + (error 1))) + ;; If `org-board-default-browser' has been set to a function, + ;; try calling that function, and on a failure continue down the cond. + ;; Note: Relies on and not evaluating the second arg if the first is false. + ((and (functionp org-board-default-browser) + (condition-case err + (progn + (funcall org-board-default-browser filename-string) + t) + (error (progn + (message "org-board-default-browser function failed: %s" err) + nil)))) 0) ;; Otherwise, use `open' on a Mac, `xdg-open' on GNU/Linux and ;; BSD, and prompt for a shell command otherwise. (What would ;; be the best for Windows?) Return the exit code of the ;; process call. + (:else (call-process (cond ((eq system-type 'darwin) "open") ((member system-type '(gnu gnu/linux gnu/kfreebsd)) "xdg-open") (t (read-shell-command "Open current file with: "))) nil nil nil - filename-string)))) + filename-string))))) ;;;###autoload (defun org-board-extend-default-path (filename-string) From 4cea2021b93e884ad3a920d48e8ad28451e6f5e2 Mon Sep 17 00:00:00 2001 From: swapn Date: Fri, 3 Mar 2023 18:54:13 -0500 Subject: [PATCH 3/5] Allow a user-defined list of browser functions. --- org-board.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/org-board.el b/org-board.el index 84559ef..329dd3c 100644 --- a/org-board.el +++ b/org-board.el @@ -879,6 +879,19 @@ non-nil." (error (progn (message "org-board-default-browser function failed: %s" err) nil)))) 0) + ;; If org-board-default-browser is a list of functions (i.e. (list #'eww)), + ;; try them in order to see if any work, otherwise signal a failure. + ((listp org-board-default-browser) + (do ((idx 0 (1+ idx))) + ((>= idx (length org-board-default-browser))) + (let ((b (nth idx org-board-default-browser))) + (condition-case err + (progn + (funcall b filename-string) + (cl-return 0)) + (error (progn + (message "%s failed: %s" b err) + 1)))))) ;; Otherwise, use `open' on a Mac, `xdg-open' on GNU/Linux and ;; BSD, and prompt for a shell command otherwise. (What would ;; be the best for Windows?) Return the exit code of the From ca209b27fbcad7859a88a6ae6e442ce0ca3305c7 Mon Sep 17 00:00:00 2001 From: swapn Date: Sat, 4 Mar 2023 18:51:20 -0500 Subject: [PATCH 4/5] Remove cl-lib dependency from org-board-open-with --- org-board.el | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/org-board.el b/org-board.el index 329dd3c..a330184 100644 --- a/org-board.el +++ b/org-board.el @@ -871,31 +871,32 @@ non-nil." ;; If `org-board-default-browser' has been set to a function, ;; try calling that function, and on a failure continue down the cond. ;; Note: Relies on and not evaluating the second arg if the first is false. - ((and (functionp org-board-default-browser) - (condition-case err - (progn - (funcall org-board-default-browser filename-string) - t) - (error (progn - (message "org-board-default-browser function failed: %s" err) - nil)))) 0) + ((functionp org-board-default-browser) + (condition-case err + (progn + (funcall org-board-default-browser filename-string) + 0) + (error + (progn + ;; (message "org-board-default-browser function failed: %s" err) + 1)))) ;; If org-board-default-browser is a list of functions (i.e. (list #'eww)), ;; try them in order to see if any work, otherwise signal a failure. ((listp org-board-default-browser) - (do ((idx 0 (1+ idx))) - ((>= idx (length org-board-default-browser))) - (let ((b (nth idx org-board-default-browser))) - (condition-case err - (progn - (funcall b filename-string) - (cl-return 0)) - (error (progn - (message "%s failed: %s" b err) - 1)))))) - ;; Otherwise, use `open' on a Mac, `xdg-open' on GNU/Linux and - ;; BSD, and prompt for a shell command otherwise. (What would - ;; be the best for Windows?) Return the exit code of the - ;; process call. + (let ((browser-call (lambda (b) (condition-case err + (progn + (funcall b filename-string) + 0) + (error 1))))) + (catch 'valid-browser-found + (dolist (current-browser org-board-default-browser) + (if (= (funcall browser-call current-browser) 0) + (throw 'valid-browser-found 0) + 1))))) + ;; Otherwise, use `open' on a Mac, `xdg-open' on GNU/Linux and + ;; BSD, and prompt for a shell command otherwise. (What would + ;; be the best for Windows?) Return the exit code of the + ;; process call. (:else (call-process (cond ((eq system-type 'darwin) "open") From 0b04ffdb49c626361c95d374bb47817896661597 Mon Sep 17 00:00:00 2001 From: swapn Date: Sat, 4 Mar 2023 18:57:31 -0500 Subject: [PATCH 5/5] Reduce redundancy in org-board-archive --- org-board.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org-board.el b/org-board.el index a330184..2c70508 100644 --- a/org-board.el +++ b/org-board.el @@ -702,6 +702,7 @@ added as a link in the `ARCHIVED_AT' property." (output-directory (concat (file-name-as-directory attach-directory) (file-name-as-directory timestamp))) (org-id-token (org-id-get)) + (org-entry (org-display-outline-path nil t "/" t)) (link-to-output (if (not org-board-make-relative) (concat "[[file:" output-directory "][" timestamp "]]") @@ -711,9 +712,8 @@ added as a link in the `ARCHIVED_AT' property." options urls))) - (org-id-goto org-id-token) (process-put wget-process 'org-entry - (org-display-outline-path nil t "/" t)) + org-entry) (process-put wget-process 'wget-output-directory output-directory) (process-put wget-process 'org-id