Skip to content

Commit

Permalink
Fix hyrolo-org-mode to conditionalize ref to org-fold if unbound
Browse files Browse the repository at this point in the history
Fix to repair mixed version Org installation so Hyperbole works
by calling new function `hsys-org-fix-version' from `hyperb:init'.
  • Loading branch information
rswgnu committed Jan 13, 2024
1 parent 19aced9 commit d5a9715
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 50 deletions.
26 changes: 24 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
2024-01-13 Bob Weiner <[email protected]>

* hsys-org.el (hsys-org-fix-version): Add. Add .org suffix to
'auto-mode-alist' as it may be removed in this function.
hyperbole.el (hyperb:init): Add call to 'hsys-org-fix-version' when
detect a mixed version installation of Org, typically part of
built-in Org loaded before loading a newer packaged version.

* hargs.el (hargs:at-p): Fix 'no-default' arg handling to not select
non-existent dirs and files when no-default is true.

* hsys-xref.el (hsys-xref-definitions): Fix to pass symbol, not string to
'ert-test-boundp'.

* hmouse-drv.el (hkey-help-show): Rename local var from 'org-help' to
'hkey-org-help' to eliminate any confusion that this is an Org variable.

* hyrolo.el (hyrolo-any-file-type-problem-p): Print error buffer to stdout
when run noninteractively (batch mode).

* hyrolo.el (hyrolo-org-mode): Conditionalize org-fold usage as it is only
available in newer Org versions. Add missing forward declarations.

* hyrolo.el (hyrolo-org-mode): Add newer Org 9.7-pre hide/show support.
test/hyrolo-tests.el (hyrolo-tests--outline-hide-show-heading,
hyrolo-tests--outline-show-when-moving-out-of-hidden-line):
The above change fixes these tests, so they have been re-enabled.

* hmouse-tag.el (smart-lisp-identifier-chars): Add @ char as advised functions
use the orig-function@advice-wrapper-name to refer to the advice.
* hmouse-tag.el (smart-lisp-identifier-chars): Add @ char as advised
functions use the orig-function@advice-wrapper-name to refer to the
advice.

* hpath.el (hpath:variables): Move 'load-path' and 'exec-path' before
'Info-directory-list' as they should be higher priority matches.
Expand Down
10 changes: 5 additions & 5 deletions hargs.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 31-Oct-91 at 23:17:35
;; Last-Mod: 1-Dec-23 at 11:23:52 by Bob Weiner
;; Last-Mod: 13-Jan-24 at 16:09:00 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -658,9 +658,9 @@ Handles all of the interactive argument types that `hargs:iform-read' does."
((hpath:at-p 'file))
;; Unquoted remote file name.
((hpath:is-p (hpath:remote-at-p) 'file))
;; Possibly non-existent file name
((when no-default (hpath:at-p 'file 'non-exist)))
(no-default nil)
;; Possibly non-existent file name
((hpath:at-p 'file 'non-exist))
((buffer-file-name))))
((eq hargs:reading-type 'directory)
(cond ((derived-mode-p 'dired-mode)
Expand All @@ -672,9 +672,9 @@ Handles all of the interactive argument types that `hargs:iform-read' does."
((hpath:at-p 'directory))
;; Unquoted remote directory name.
((hpath:is-p (hpath:remote-at-p) 'directory))
;; Possibly non-existent directory name
((when no-default (hpath:at-p 'directory 'non-exist)))
(no-default nil)
;; Possibly non-existent directory name
((hpath:at-p 'directory 'non-exist))
(default-directory)))
((eq hargs:reading-type 'string)
(or (hargs:delimited "\"" "\"") (hargs:delimited "'" "'")
Expand Down
8 changes: 4 additions & 4 deletions hmouse-drv.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 04-Feb-90
;; Last-Mod: 3-Jan-24 at 02:24:39 by Bob Weiner
;; Last-Mod: 13-Jan-24 at 15:32:40 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ the current window. By default, it is displayed according to the setting of
`hpath:display-where'."
(if (bufferp buffer) (setq buffer (buffer-name buffer)))
(if (null buffer) (setq buffer (buffer-name (current-buffer))))
(let ((org-help (and (stringp buffer) (string-match "\\`\\*Org Help\\*" buffer)))
(let ((hkey-org-help (and (stringp buffer) (string-match "\\`\\*Org Help\\*" buffer)))
(owind (selected-window)))
(and (stringp buffer)
(string-match "^\\*Help\\|Help\\*$" buffer)
Expand All @@ -1262,7 +1262,7 @@ the current window. By default, it is displayed according to the setting of
(selected-window))
(t (hpath:display-buffer buf)))))
;; Ignore org-mode's temp help buffers which it handles on its own.
(when (and wind (not org-help))
(when (and wind (not hkey-org-help))
(setq minibuffer-scroll-window wind)
;; Don't use help-mode in buffers already set up with a
;; quit-key to bury the buffer, e.g. minibuffer completions,
Expand All @@ -1275,7 +1275,7 @@ the current window. By default, it is displayed according to the setting of
(when (derived-mode-p 'help-mode)
(local-set-key "q" #'hkey-help-hide)))))
;; If in an *Org Help* buffer, reselect the Org buffer.
(when org-help
(when hkey-org-help
(select-window owind))
;; If in a *Completions* buffer, re-select the window that
;; generated the completions.
Expand Down
44 changes: 43 additions & 1 deletion hsys-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 2-Jul-16 at 14:54:14
;; Last-Mod: 13-Jan-24 at 02:28:50 by Bob Weiner
;; Last-Mod: 13-Jan-24 at 16:28:29 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -152,6 +152,48 @@ an error."
;;; Public functions
;;; ************************************************************************

;;;###autoload
(defun hsys-org-fix-version ()
"If multiple Org versions are loaded, use the one first on `load-path'."
(let ((org-dir (ignore-errors (org-find-library-dir "org")))
(org-install-dir
(ignore-errors (org-find-library-dir "org-loaddefs"))))
(unless (and org-dir org-install-dir (string-equal org-dir org-install-dir))
;; Ensure using any local available packaged version of Org mode
;; rather than built-in which may have been activated before
;; load-path was set correctly. Avoids mixed version load of Org.
(mapc (lambda (lib-sym) (when (featurep lib-sym) (unload-feature lib-sym t)))
'(org org-version org-keys org-compat ol org-table org-macs org-id org-element org-list
org-element org-src org-fold))
(package-initialize)
(let ((pkg-desc (car (cdr (assq 'org package-archive-contents)))))
(package-activate pkg-desc t))
;; Not all versions of org include this variable, so set it
(setq org--inhibit-version-check nil
org-list-allow-alphabetical nil)
;; Otherwise, `font-lock-ensure' make invoke an undefined matcher
;; function, `org-fontify-inline-src-blocks'.
(load "org-src")
;; Otherwise, `org-id-get-create' may call undefined
;; `org-element-cache-active-p'
(load "org-element")
;; Otherwise, {M-RET} may not be bound to a key
(load "org-keys")
;; Otherwise, `org-file-name-concat' may be undefined
(load "org-compat")
;; Otherwise, `org--inhibit-version-check' may be undefined
(load "org-macs")
;; Otherwise, `org-list-allow-alphabetical' may be undefined
(load "org-list")
;; Otherwise, `org-fold--advice-edit-commands' may be undefined
(load "org-fold")
;; Otherwise, `org-link--description-folding-spec' may be undefined
(load "ol")
(cl-flet ((require (lambda (lib-sym &optional _filename _noerror)
(load (symbol-name lib-sym)))))
(require 'org))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)))))

;;;###autoload
(defun hsys-org-meta-return-shared-p ()
"Return non-nil if hyperbole-mode is active and shares the org-meta-return key."
Expand Down
4 changes: 2 additions & 2 deletions hsys-xref.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 24-Aug-91
;; Last-Mod: 9-Jan-24 at 12:07:34 by Bob Weiner
;; Last-Mod: 13-Jan-24 at 15:55:13 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -31,7 +31,7 @@
(let* ((elisp-flag (smart-emacs-lisp-mode-p))
(xref-backend (or (and elisp-flag
(fboundp 'ert-test-boundp)
(ert-test-boundp identifier)
(ert-test-boundp (intern-soft identifier))
(boundp 'xref-etags-mode)
'etags)
(xref-find-backend)))
Expand Down
14 changes: 11 additions & 3 deletions hyperbole.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
;; Maintainer: Mats Lidell <[email protected]>
;; Maintainers: Robert Weiner <[email protected]>, Mats Lidell <[email protected]>
;; Created: 06-Oct-92 at 11:52:51
;; Last-Mod: 3-Jan-24 at 02:27:05 by Bob Weiner
;; Last-Mod: 13-Jan-24 at 16:28:45 by Bob Weiner
;; Released: 03-Dec-23
;; Version: 9.0.0
;; Keywords: comm, convenience, files, frames, hypermedia, languages, mail, matching, mouse, multimedia, outlines, tools, wp
Expand Down Expand Up @@ -496,6 +496,13 @@ frame, those functions by default still return the prior frame."
'buttons
t)))
;;
;; This next function call must be run before any tests involving Org
;; in case the user has installed a new version of Org but Emacs has
;; loaded parts of Org before his load path is finalized. It loads
;; the newer version of Org, if any, assuming `load-path' is configured
;; correctly.
(hsys-org-fix-version)
;;
;; When vertico-mode is used, vertico-mouse-mode is needed for the
;; Action Key to properly select completions from the candidate
;; list, so force its usage when vertico-mode is invoked.
Expand All @@ -505,9 +512,10 @@ frame, those functions by default still return the prior frame."
;;
;; Hyperbole initialization is complete.
(message "Initializing Hyperbole...done"))


;; This call loads the rest of the Hyperbole system.
(require 'hinit)
;; This call loads the rest of the Hyperbole system.
(require 'hinit)

(defun hyperbole--enable-mode ()
"Enable Hyperbole global minor mode."
Expand Down
29 changes: 19 additions & 10 deletions hyrolo.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@
(defvar helm-org-rifle-show-level-stars)
(defvar hproperty:but-emphasize-flag)
(defvar markdown-regex-header)
(defvar org-fold-core-style)
(defvar org-link--link-folding-spec)
(defvar org-roam-db-autosync-mode)
(defvar org-roam-directory)
(defvar plstore-cache-passphrase-for-symmetric-encryption)
(defvar reveal-auto-hide)

(declare-function consult-grep "ext:consult")
(declare-function consult-ripgrep "ext:consult")
Expand All @@ -79,6 +82,8 @@
(declare-function helm-org-rifle-org-directory "ext:helm-org-rifle")
(declare-function helm-org-rifle-show-full-contents "ext:helm-org-rifle")
(declare-function kotl-mode:to-valid-position "kotl/kotl-mode")
(declare-function org-fold-initialize "org-fold")
(declare-function org-fold-core-set-folding-spec-property "org-fold")
(declare-function org-roam-db-autosync-mode "ext:org-roam")
(declare-function xml-node-child-string "ext:google-contacts")
(declare-function xml-node-get-attribute-type "ext:google-contacts")
Expand Down Expand Up @@ -2446,6 +2451,9 @@ package is not installed."
(terpri)
;; (setq backtrace-view (plist-put backtrace-view :show-locals t))
(backtrace)))
(when noninteractive
(princ (with-current-buffer (get-buffer "*HyRolo Errors*")
(buffer-string))))
t)))

(defun hyrolo-buffer-exists-p (hyrolo-buf)
Expand Down Expand Up @@ -2605,16 +2613,17 @@ Any non-nil value returned is a cons of (<entry-name> . <entry-source>)."
;; checks will pass.
(put 'hyrolo-org-mode 'derived-mode-parent 'org-mode)

(when (and org-link-descriptive
(eq org-fold-core-style 'overlays))
(add-to-invisibility-spec '(org-link)))
(org-fold-initialize (or (and (stringp org-ellipsis) (not (equal "" org-ellipsis)) org-ellipsis)
"..."))
(make-local-variable 'org-link-descriptive)
(when (eq org-fold-core-style 'overlays) (add-to-invisibility-spec '(org-hide-block . t)))
(if org-link-descriptive
(org-fold-core-set-folding-spec-property (car org-link--link-folding-spec) :visible nil)
(org-fold-core-set-folding-spec-property (car org-link--link-folding-spec) :visible t))
(when (featurep 'org-fold) ;; newer Org versions
(when (and org-link-descriptive
(eq org-fold-core-style 'overlays))
(add-to-invisibility-spec '(org-link)))
(org-fold-initialize (or (and (stringp org-ellipsis) (not (equal "" org-ellipsis)) org-ellipsis)
"..."))
(make-local-variable 'org-link-descriptive)
(when (eq org-fold-core-style 'overlays) (add-to-invisibility-spec '(org-hide-block . t)))
(if org-link-descriptive
(org-fold-core-set-folding-spec-property (car org-link--link-folding-spec) :visible nil)
(org-fold-core-set-folding-spec-property (car org-link--link-folding-spec) :visible t)))

(setq-local hyrolo-entry-regexp "^\\(\\*+\\)\\([ ]+\\)"
hyrolo-hdr-and-entry-regexp (concat hyrolo-hdr-prefix-regexp hyrolo-entry-regexp)
Expand Down
1 change: 0 additions & 1 deletion test/demo-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@
(should (not (org-check-for-hidden 'headlines)))
(save-excursion
(action-key))
;;; (org-hide-entry)
(should (org-check-for-hidden 'headlines)))))

;; Manifest
Expand Down
22 changes: 2 additions & 20 deletions test/hui-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 30-Jan-21 at 12:00:00
;; Last-Mod: 30-Dec-23 at 00:00:18 by Bob Weiner
;; Last-Mod: 13-Jan-24 at 16:30:08 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -935,25 +935,7 @@ With point on label suggest that ibut for rename."
(ert-deftest hui--link-possible-types ()
"Verify right type is selected from referent buffer."

;; Ensure using any local available packaged version of Org mode rather than built-in
;; which may have been activated before load-path was set correctly.
;; Avoids mixed version load of Org.
(mapc (lambda (lib-sym) (when (featurep lib-sym) (unload-feature lib-sym t)))
'(org org-version org-keys org-compat ol org-table org-macs org-id org-element org-list))
(package-initialize)
(let ((pkg-desc (car (cdr (assq 'org package-archive-contents)))))
(package-activate pkg-desc t))
;; Not all versions of org include this variable, so set it
(setq org--inhibit-version-check nil
org-list-allow-alphabetical nil)
(load "org-keys") ;; Otherwise, {M-RET} may not be bound to a key
(load "org-compat") ;; Otherwise, `org-file-name-concat' may be undefined
(load "org-macs") ;; Otherwise, `org--inhibit-version-check' may be undefined
(load "org-list") ;; Otherwise, `org-list-allow-alphabetical' may be undefined
(load "ol") ;; Otherwise, `org-link--description-folding-spec' may be undefined
(cl-flet ((require (lambda (lib-sym &optional _filename _noerror)
(load (symbol-name lib-sym)))))
(require 'org))
(hsys-org-fix-version)

;; Org Roam or Org Id link-to-org-id
(let ((file (make-temp-file "hypb" nil ".org")))
Expand Down
4 changes: 2 additions & 2 deletions test/hy-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 30-Jan-21 at 12:00:00
;; Last-Mod: 7-Jan-24 at 00:56:08 by Mats Lidell
;; Last-Mod: 13-Jan-24 at 16:21:45 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand All @@ -19,7 +19,7 @@
;;; Code:

(require 'ert)
(require 'hmouse-drv) ;For `action-key'.
(require 'hmouse-drv) ; For `action-key'
(eval-when-compile (require 'cl-lib))

(defun hy-test-helpers:consume-input-events ()
Expand Down

0 comments on commit d5a9715

Please sign in to comment.