branch: externals/hyperbole commit f017340a28e06ad7d9683db4fb6e2b15f85f0ee5 Author: bw <r...@gnu.org> Commit: bw <r...@gnu.org>
hywiki.el - Fix, improve a number of features and defaults. Ensure page creation fails if page name does not match HyWikiWord format. Enable `hyperbole-mode' whenever `hywiki-mode' is enabled since it uses it. --- ChangeLog | 19 +++++++ hui-mouse.el | 24 ++++---- hyperbole.el | 8 ++- hywiki.el | 157 +++++++++++++++++++++++++++++++++------------------ man/hyperbole.texi | 24 ++++---- test/hywiki-tests.el | 3 +- 6 files changed, 151 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ea46df538..91c8aa866f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2024-06-02 Bob Weiner <r...@gnu.org> + +* hyperbole.el (hyperbole--disable-mode): Add disabling of 'hywiki-mode'. + +* hywiki.el (hywiki-active-in-current-buffer-p): Exclude buffers whose + major-modes are 'special, e.g. Dired mode. + (hywiki-word-highlight-flag): Clarify behavior. + (hywiki-highlight-all-in-prog-modes): Change to a `defcustom'. + (hywiki-get-page-files): Change to find files that end with + 'hywiki-file-suffix' only. + (defib hywiki): Rename to 'hywiki-word' since activates on a + HyWikiWord. + (defcustom :group): Change from hyperbole-wiki to hyperbole-hywiki. + (hywiki-mode): Enable 'hyperbole-mode' which it uses. + (hywiki-mode-lighter): Add so can customize mode-line indicator. + (hywiki-excluded-major-modes): Rename to 'hywiki-exclude-major-modes'. + (hywiki-add-page): Fix case-sensitive check of page-name validity + by calling 'hywiki-is-wikiword'. + 2024-06-01 Mats Lidell <ma...@gnu.org> * test/hywiki-tests.el (hywiki-tests--hywiki-add-page--adds-file-in-wiki-folder) diff --git a/hui-mouse.el b/hui-mouse.el index e9496d105a..42f80cbfc4 100644 --- a/hui-mouse.el +++ b/hui-mouse.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 04-Feb-89 -;; Last-Mod: 29-May-24 at 00:15:48 by Bob Weiner +;; Last-Mod: 2-Jun-24 at 11:40:22 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1803,19 +1803,19 @@ Active when `hsys-org-enable-smart-keys' is non-nil, When the Action Key is pressed: - 1. If on an Org todo keyword, cycle through the keywords in - that set or if final done keyword, remove it. + 1. On an Org todo keyword, cycle through the keywords in that + set or if final done keyword, remove it. - 2. If on an Org agenda view item, jump to the item for editing. + 2. On an Org agenda view item, jump to the item for editing. 3. Within a radio or internal target or a link to it, jump between the target and the first link to it, allowing two-way navigation. - 4. Follow other internal links in Org mode files. + 4. On another internal link in an Org mode file, jump to its referent. - 5. Follow Org mode external links. + 5. On an Org mode external link, jump to its referent. - 6. When on a Hyperbole button, activate the button. + 6. On a Hyperbole button, activate the button. 7. With point on the :dir path of a code block definition, display the directory given by the path. @@ -1824,8 +1824,8 @@ When the Action Key is pressed: or #+end_example header, execute the code block via the Org mode standard binding of {\\`C-c' \\`C-c'}, (org-ctrl-c-ctrl-c). - 9. When point is on an Org mode heading, cycle the view of the subtree - at point. + 9. With point on an Org mode heading, cycle the view of the subtree at + point. 10. In any other context besides the end of a line, invoke the Org mode standard binding of {M-RET}, (org-meta-return). @@ -1833,10 +1833,10 @@ When the Action Key is pressed: When the Assist Key is pressed, it behaves just like the Action Key except in these contexts: - 1. If on an Org todo keyword, move to the first todo keyword in - the next set, if any. + 1. On an Org todo keyword, move to the first todo keyword in the next + set, if any. - 2. If on an Org mode link or agenda view item, display Hyperbole + 2. On an Org mode link or agenda view item, display Hyperbole context-sensitive help. 3. On a Hyperbole button, perform the Assist Key function, generally diff --git a/hyperbole.el b/hyperbole.el index 7c7257b3a6..f207f925ab 100644 --- a/hyperbole.el +++ b/hyperbole.el @@ -9,7 +9,7 @@ ;; Maintainer: Mats Lidell <ma...@gnu.org> ;; Maintainers: Robert Weiner <r...@gnu.org>, Mats Lidell <ma...@gnu.org> ;; Created: 06-Oct-92 at 11:52:51 -;; Last-Mod: 28-May-24 at 23:04:52 by Bob Weiner +;; Last-Mod: 2-Jun-24 at 13:22:35 by Bob Weiner ;; Released: 10-Mar-24 ;; Version: 9.0.2pre ;; Keywords: comm, convenience, files, frames, hypermedia, languages, mail, matching, mouse, multimedia, outlines, tools, wp @@ -511,8 +511,8 @@ frame, those functions by default still return the prior frame." (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." @@ -540,6 +540,8 @@ frame, those functions by default still return the prior frame." (defun hyperbole--disable-mode () "Disable Hyperbole keys, menus and hooks." + ;; Deactivate hywiki-mode + (hywiki-mode 0) ;; Deactivate hyperbole-mode ;; Delete Hyperbole menu from all menubars. (hui-menu-remove Hyperbole) diff --git a/hywiki.el b/hywiki.el index c2055d1be3..2e7d7fddff 100644 --- a/hywiki.el +++ b/hywiki.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 21-Apr-24 at 22:41:13 -;; Last-Mod: 29-May-24 at 00:53:33 by Bob Weiner +;; Last-Mod: 2-Jun-24 at 11:52:44 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -15,49 +15,76 @@ ;;; Commentary: ;; ;; This is Hyperbole's markup-free personal Wiki system for -;; note-taking and automatic WikiWord hyperlinking. A `HyWiki word' -;; starts with a capitalized letter and contains only upper and -;; lowercase letters. `HyWiki pages' are Org or other text mode -;; files with HyWiki word names (the page name) plus a file-type -;; suffix which are stored within `hywiki-directory'. +;; note-taking and automatic wiki word hyperlinking. + +;; A `HyWikiWord' is a low-priority Hyperbole implicit button type +;; (named hywiki-word) that starts with a capitalized letter and +;; contains only upper and lowercase letters. Such words +;; automatically link to `HyWiki pages', which are Org mode files +;; with HyWikiWord names (the page name) plus a ".org" suffix, stored +;; within the directory given by `hywiki-directory'. Such links are +;; activated with a press of the Action Key {M-RET} within the link. ;; -;; To create a new HyWiki page or to jump to one, simply create an -;; Org link in any buffer with the prefix "hy:" followed by a -;; capitalized alpha characters-only WikiWord, e.g. [[hy:Emacs]], and -;; then press the Action Key on the link to jump to the associated -;; page; new pages are automatically created. - -;; If you set `hywiki-org-link-type-required' to `nil', then -;; you don't need the prefix, e.g. [[Emacs]] and existing HyWiki page -;; names will override Org's standard handling of such links. To -;; prevent Org mode's binding of {M-RET} from splitting lines and -;; creating new headlines when on a HyWiki word whose page has not -;; yet been created, set `hsys-org-enable-smart-keys' to 't' so that +;; Once Hyperbole has been loaded and activated, HyWikiWords (with or +;; without delimiters) are automatically highlighted and active in +;; the following contexts: +;; - HyWiki page buffers; +;; - non-special text buffers when `hywiki-mode' is enabled; +;; - comments of programming buffers when `hywiki-mode' is enabled. +;; +;; As HyWikiWords are typed, highlighting occurs after a trailing +;; whitespace or punctuation character is added, or when an opening +;; or closing parenthesis or curly brace is added to surround the +;; HyWikiWord. +;; +;; To create a new HyWiki page or to jump to one, simply type a +;; HyWikiWord in a valid context and then press the Action Key on it. +;; If the associated page exists, jump to it. If it doesn't, create +;; it and display its empty buffer for editing. editing. Highlight +;; all visible Instances of the associated HyWikiWord as well. +;; +;; You can also create Org links to HyWikiWords in any non-special text +;; buffer by surrounding them with double square brackets and the +;; 'hy:' prefix, as in: [[hy:MyWikiWord]]. If you set +;; `hywiki-org-link-type-required' to `nil', then you don't need the +;; prefix, e.g. [[MyWikiWord]]; existing HyWiki page names then will +;; override Org's standard handling of such links. To prevent Org +;; mode's binding of {M-RET} from splitting lines and creating new +;; headlines when on a HyWiki word whose page has not yet been +;; created, set `hsys-org-enable-smart-keys' to `t' so that ;; Hyperbole's Action Key does the right thing in this context. ;; ;; HyWiki pages are created in `hywiki-directory'. Within such -;; pages, WikiWords (the names of HyWiki pages) work without the need +;; pages, HyWikiWords (the names of HyWiki pages) work without the need ;; for any delimiters. Simply type them out, e.g. Emacs and if a -;; page exists for the word, it is automatically highlighted when: +;; page exists for the word, it is ;; - a HyWiki page file is read in ;; - a whitespace character, ')', '}', or Org-mode punctuation/symbol ;; character is inserted following a HyWiki word ;; - the Action Key is pressed to activate a HyWiki word button. ;; ;; HyWiki links can also link to a section headline within a page by -;; simply following the page name a '#' character and then the +;; simply following the page name with a '#' character and then the ;; section headline name. For example, if your Emacs page has a -;; 'Major Modes section, then either [[hy:Emacs#Major Modes]] or -;; Emacs#Major-Modes will work as a link to that section. Note that -;; without the square bracket delimiters, you must convert spaces in -;; section names to '-' characters. +;; "Major Modes" section, then either Emacs#Major-Modes or +;; [[hy:Emacs#Major Modes]] will work as a link to that section. +;; Note that without the square bracket delimiters, you must convert +;; spaces in section names to '-' characters. As long as the page +;; exists, section links are highlighted regardless of whether +;; associated sections exist or not. +;; +;; The custom setting, `hywiki-word-highlight-flag' (default = 't), +;; means HyWikiWords will be auto-highlighted within HyWiki pages. +;; Outside of such pages, `hywiki-mode' must also be enabled for such +;; auto-highlighting. ;; -;; Although HyWiki creates new pages in Org mode, you can manually -;; insert pages in Markdown or other text modes within -;; `hywiki-directory' and then link to them. You can also change the -;; default `hywiki-file-suffix' to something else, like ".md" to have -;; HyWiki use Markdown mode for its pages. This usage has not yet -;; been tested though, so use at your own risk. +;; The custom setting, `hywiki-exclude-major-modes' (default = nil), is +;; a list of major modes to exclude from HyWikiWord auto-highlighting +;; and recognition. +;; +;; The custom setting, `hywiki-highlight-all-in-prog-modes' (default = +;; '(lisp-interaction-mode)), is a list of programming major modes to +;; highlight HyWikiWords outside of comments. ;;; Code: ;;; ************************************************************************ @@ -87,15 +114,28 @@ ;;; ************************************************************************ (defcustom hywiki-word-highlight-flag t - "Non-nil means automatically highlight non-Org link HyWiki word hyperbuttons." + "HyWiki highlights non-Org link HyWikiWords only when this is non-nil. +Outside of HyWiki pages, `hywiki-mode' must also be enabled for +auto-HyWikiWord highlighting." :type 'boolean :initialize #'custom-initialize-default - :group 'hyperbole-wiki) + :group 'hyperbole-hywiki) -(defcustom hywiki-excluded-major-modes nil +(defcustom hywiki-exclude-major-modes nil "List of major modes to exclude from HyWiki word highlighting and recognition." :type '(list symbol) - :group 'hyperbole-wiki) + :group 'hyperbole-hywiki) + +(defcustom hywiki-highlight-all-in-prog-modes '(lisp-interaction-mode) + "List of programming major modes to highlight HyWikiWords outside of comments." + :type '(list symbol) + :group 'hyperbole-hywiki) + +(defcustom hywiki-mode-lighter " HyWiki" + "String to display in mode line when the HyWiki global minor mode is enabled. +Use nil for no HyWiki mode indicator." + :type 'string + :group 'hyperbole-hywiki) (defvar hywiki-file-suffix ".org" "File suffix (including period) to use when creating HyWiki pages.") @@ -103,9 +143,6 @@ (defvar hywiki-directory '"~/hywiki/" "Directory in which to find HyWiki page files.") -(defvar hywiki-highlight-all-in-prog-modes '(lisp-interaction-mode) - "List of programming major modes to highlight HyWikiWords outside of comments.") - (defvar hywiki-non-character-commands '(;; Org mode org-cycle ;; TAB @@ -166,13 +203,13 @@ the HyWiki word and grouping 2 is the #section with the # included.") (((min-colors 88)) (:foreground "orange")) (t (:background "orange"))) "Face for HyWiki word highlighting." - :group 'hyperbole-wiki) + :group 'hyperbole-hywiki) (defcustom hywiki-word-face 'hywiki--word-face "Hyperbole face for HyWiki word highlighting." :type 'face :initialize #'custom-initialize-default - :group 'hyperbole-wiki) + :group 'hyperbole-hywiki) ;;; ************************************************************************ ;;; Private variables @@ -275,20 +312,27 @@ See the Info documentation at \"(hyperbole)HyWiki\". \\{hywiki-mode-map}" :global t - :lighter " HyWiki" + :lighter hywiki-mode-lighter :keymap hywiki-mode-map - :group 'hyperbole-wiki + :group 'hyperbole-hywiki (if hywiki-mode - (progn (unless hywiki-mode-map - (setq hywiki-mode-map (make-sparse-keymap))) + ;; enable mode + (progn + ;; Need hyperbole-mode + (if (boundp 'hyperbole-mode) + (unless hyperbole-mode (hyperbole-mode 1)) + (error "(hywiki-mode): `hyperbole-mode' must be defined before invoking `hywiki-mode'")) + (unless hywiki-mode-map + (setq hywiki-mode-map (make-sparse-keymap))) ;; Self-insert punct/sym keys that trigger wiki-word ;; highlighting via `hywiki-buttonize-character-commands' ;; in `hywiki-mode'. - (unless hywiki--buttonize-characters - (setq hywiki--buttonize-characters - (concat " \t\r\n()<>[]{}'" (hywiki-get-buttonize-characters)))) - (add-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands) - (add-hook 'pre-command-hook 'hywiki-buttonize-non-character-commands 95)) + (unless hywiki--buttonize-characters + (setq hywiki--buttonize-characters + (concat " \t\r\n()<>[]{}'" (hywiki-get-buttonize-characters)))) + (add-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands) + (add-hook 'pre-command-hook 'hywiki-buttonize-non-character-commands 95)) + ;; disable mode (remove-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands) (remove-hook 'pre-command-hook 'hywiki-buttonize-character-commands)) (hywiki-highlight-page-names-in-frame (selected-frame))) @@ -297,7 +341,7 @@ See the Info documentation at \"(hyperbole)HyWiki\". ;;; Public Implicit Button and Action Types ;;; ************************************************************************ -(defib hywiki () +(defib hywiki-word () "When on a HyWiki word, display its page and optional section." (let ((page-name (hywiki-at-wikiword))) (when page-name @@ -355,8 +399,9 @@ successfully finding a page and reading it into a buffer, run (defun hywiki-active-in-current-buffer-p () "Return non-nil if HyWiki word links are active in the current buffer." - (and hywiki-word-highlight-flag - (not (apply #'derived-mode-p hywiki-excluded-major-modes)) + (and (not (eq (get major-mode 'mode-class) 'special)) + hywiki-word-highlight-flag + (not (apply #'derived-mode-p hywiki-exclude-major-modes)) (or hywiki-mode (hywiki-in-page-p)))) (defun hywiki-add-to-page (page-name text start-flag) @@ -718,11 +763,13 @@ No validation of PAGE-NAME is done." (defun hywiki-get-page-files () "Return the list of existing HyWiki page file names. -These may have any alphanumeric file suffix, if files were added manually." +These must end with `hywiki-file-suffix'." (when (stringp hywiki-directory) (make-directory hywiki-directory t) (when (file-readable-p hywiki-directory) - (directory-files-recursively hywiki-directory (concat "^" hywiki-word-regexp "\\.[A-Za-z0-9]+$"))))) + (directory-files-recursively + hywiki-directory (concat "^" hywiki-word-regexp + (regexp-quote hywiki-file-suffix) "$"))))) (defun hywiki-get-page-hasht () "Return hash table of existing HyWiki pages." @@ -738,7 +785,7 @@ return nil. Use `hywiki-get-page' to determine whether a HyWiki page exists." (if (and (stringp page-name) (not (string-empty-p page-name)) - (string-match hywiki-word-with-optional-section-exact-regexp page-name)) + (hywiki-is-wikiword page-name)) (progn (when (match-string-no-properties 2 page-name) ;; Remove any #section suffix in PAGE-NAME. diff --git a/man/hyperbole.texi b/man/hyperbole.texi index 79f7fc2c34..3f5b8a7de2 100644 --- a/man/hyperbole.texi +++ b/man/hyperbole.texi @@ -25,8 +25,8 @@ @set txicodequoteundirected @set txicodequotebacktick -@set UPDATED April, 2024 -@set UPDATED-MONTH April 2024 +@set UPDATED June, 2024 +@set UPDATED-MONTH June 2024 @set EDITION 9.0.2pre @set VERSION 9.0.2pre @@ -159,7 +159,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</P> <PRE> Edition 9.0.2pre -Printed April 16, 2024. +Printed June 2, 2024. Published by the Free Software Foundation, Inc. Author: Bob Weiner @@ -201,7 +201,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @example Edition 9.0.2pre -April 16, 2024 +June 2, 2024 Published by the Free Software Foundation, Inc. Author: Bob Weiner @@ -2326,13 +2326,13 @@ Within a radio or internal target or a link to it, jump between the target and the first link to it, allowing two-way navigation. @item -Follow other internal links and ID references in Org mode files. +On another internal link in an Org mode file, jump to its referent. @item -Follow Org mode external links. +On an Org mode external link, jump to its referent. @item -When on a Hyperbole button, activate the button. +On a Hyperbole button, activate the button. @item With point on the :dir path of a code block definition, display the @@ -2344,8 +2344,8 @@ or #+end_example header, execute the code block via the Org mode standard binding of @bkbd{C-c C-c}, @code{org-ctrl-c-ctrl-c}. @item -When point is on an Org mode heading, cycle the view of the subtree -at point. +With point on an Org mode heading, cycle the view of the subtree at +point. @item In any other context besides the end of a line, invoke the Org mode @@ -2358,11 +2358,11 @@ except in these contexts: @enumerate @item -If on an Org todo keyword, move to the first todo keyword in -the next set, if any. +On an Org todo keyword, move to the first todo keyword in the next +set, if any. @item -If on an Org mode link or agenda view item, display Hyperbole +On an Org mode link or agenda view item, display Hyperbole context-sensitive help. @item diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index ee8b282140..b4c8d87112 100644 --- a/test/hywiki-tests.el +++ b/test/hywiki-tests.el @@ -7,7 +7,7 @@ ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; -;; Copyright (C) 2021-2022 Free Software Foundation, Inc. +;; Copyright (C) 2024 Free Software Foundation, Inc. ;; See the "HY-COPY" file for license information. ;; ;; This file is part of GNU Hyperbole. @@ -41,7 +41,6 @@ (ert-deftest hywiki-tests--hywiki-add-page--adds-no-wiki-word-fails () "Verify add page requires a WikiWord." - :expected-result :failed ;; Should not leave erroneously created file after test but leaving ;; added error cleanup till later if it is even needed!? No file ;; should be created so only happens on error!? (If this is