Compare commits

...

3 Commits

Author SHA1 Message Date
TEC 9db9c9fbff
Mark boolean customisations as safe 2024-06-09 10:30:56 +08:00
TEC 809aef775c
Make fontification compose better
No need to clobber existing faces.
2024-06-09 10:30:56 +08:00
TEC 2aa5428b0b
Spelling/typo fixes in comments and docstrings 2024-06-09 10:30:56 +08:00
1 changed files with 53 additions and 40 deletions

View File

@ -27,7 +27,7 @@
;; something vertico + maginalia style
;;
;; TODO M-x org-glossary-find-expanded-terms
;; this would be primaraly useful for acronyms.
;; this would be primarily useful for acronyms.
;;
;; REVIEW maybe support generating the glossary/acronym etc.
;; in the file, like org-toc.?
@ -68,9 +68,9 @@
("Acronyms" . acronym)
("Index" . index)
("Text Substitutions" . substitution))
"An alist of special heading names and their correspanding type.
"An alist of special heading names and their corresponding type.
During export, all matching headings will be removed in their
entirity (including subtrees).
entirety (including subtrees).
If setting this outside of the customisation interface, be sure
to update `org-glossary--heading-names' appropriately."
@ -83,20 +83,23 @@ to update `org-glossary--heading-names' appropriately."
(defvar org-glossary--heading-names
(mapcar #'car org-glossary-headings)
"The heading names which correspand to a glossary type.")
"The heading names which correspond to a glossary type.")
(defcustom org-glossary-toplevel-only t
"Whether all glossary definition sections must be toplevel.
"Whether all glossary definition sections must be top-level.
If nil, they will be recognised anywhere in the document."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-automatic t
"Pick up on terms in plain text."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-autodetect-in-headings nil
"Whether `org-glossary-automatic' should apply in headings."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-plural-function #'org-glossary-english-plural
"A function which generates the plural form of a word."
@ -104,17 +107,19 @@ If nil, they will be recognised anywhere in the document."
(defcustom org-glossary-canonicalise-aliases nil
"Whether aliases should be canonicalised."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-group-ui t
"Group term definitions by type.
In practice, if using Emacs 28, this allows you to turn off
grouping, and add the target type to the annotation instead."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-global-terms nil
"A list of globally availible term sources.
"A list of globally available term sources.
Each term should either be a string interpreted as an #+include
keyword's value, or a plist of the form emitted by
@ -265,7 +270,8 @@ TODO rewrite for clarity."
(defcustom org-glossary-fontify-types-differently t
"Whether to use the org-glossary-TYPE-term faces.
Or just use the org-glossary-term face for everything."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-fontify-type-faces
'((glossary . org-glossary-glossary-term)
@ -297,14 +303,16 @@ See also `org-glossary-fontify-displayed-substitute'."
Requires `org-glossary-fontify-types-differently' to be non-nil.
See also `org-glossary-fontify-displayed-substitute'."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defcustom org-glossary-fontify-displayed-substitute t
"Whether to fontify displayed substitutions values.
Requires `org-glossary-display-substitute-value' to be non-nil.
See also `org-glossary-snippet-fontication-hooks'."
:type 'boolean)
:type 'boolean
:safe #'booleanp)
(defface org-glossary-term
'((t :inherit (org-agenda-date-today org-link) :weight normal))
@ -327,7 +335,7 @@ See also `org-glossary-snippet-fontication-hooks'."
"Face used for term references.")
(defface org-glossary-substituted-value
'((t :inherit default))
'((t))
"Face used for substitution values.")
(defvar-local org-glossary--terms nil
@ -396,7 +404,7 @@ If DO-IT-P is nil, then nothing will be done and TERM-SET will be returned."
term-set))
(defun org-glossary--get-terms-oneshot (&optional path-spec)
"Optain all terms defined in PATH-SPEC."
"Obtain all terms defined in PATH-SPEC."
(let* ((path-spec (org-glossary--complete-path-spec path-spec))
(path-buffer
(cond
@ -701,7 +709,7 @@ side-effect when it is provided."
(t (org-glossary--entry-type-category (org-element-lineage datum '(headline))))))
(defvar org-glossary--category-heading-tag "category"
"The tag signifying that the heading correspands to a category of terms.")
"The tag signifying that the heading corresponds to a category of terms.")
(defun org-glossary--identify-alias-terms (terms)
"Search for aliases in TERMS, and update term entries accordingly."
@ -728,7 +736,7 @@ side-effect when it is provided."
;;; Term usage
(defun org-glossary-apply-terms (terms &optional no-modify no-number keep-unused)
"Replace occurances of the TERMS with links.
"Replace occurrences of the TERMS with links.
This returns a copy of TERMS with references recorded in :uses.
When NO-MODIFY is non-nil, neither buffer content nor TERMS will be modified.
@ -1458,7 +1466,7 @@ If MARK-EXTRACTED is non-nil, extracted uses shall be marked as extracted."
(plist-get parameters :all)))
(defun org-glossary--expand-print-keyword (backend terms keyword)
"Call `org-glossary--expand-print' with paramaters and terms based on KEYWORD.
"Call `org-glossary--expand-print' with parameters and terms based on KEYWORD.
BACKEND is passed through unmodified, but TERMS may be modified depending on
the :consume parameter extracted from KEYWORD."
(let ((heading (org-element-lineage keyword '(headline org-data)))
@ -1797,30 +1805,35 @@ This should only be run as an export hook."
"Fontify the matched term."
(let ((term-entry (org-glossary--quicklookup (match-string 0)))
case-fold-search)
(font-lock-prepend-text-property
(match-beginning 0) (match-end 0)
'face
(pcase (plist-get term-entry :type)
('substitution
(if org-glossary-display-substitute-value
'org-glossary-substituted-value
'org-glossary-substitution-term))
(type
(or (alist-get type org-glossary-fontify-type-faces)
'org-glossary-term))))
(add-text-properties
(match-beginning 0) (match-end 0)
(nconc
(pcase (plist-get term-entry :type)
('substitution
(if org-glossary-display-substitute-value
`(face org-glossary-substituted-value
help-echo org-glossary--help-echo-from-textprop
mouse-face org-glossary-substitution-term
display
,(funcall
(if org-glossary-fontify-displayed-substitute
#'org-glossary--fontify-org-snippet #'identity)
(funcall
(if (string-match-p "^[[:upper:]][^[:upper:]]+$"
(match-string 0))
#'org-glossary--sentance-case #'identity)
(string-trim
(substring-no-properties
(org-element-interpret-data
(plist-get term-entry :value)))))))
'(face org-glossary-substitution-term)))
(type `(face ,(or (alist-get type org-glossary-fontify-type-faces)
'org-glossary-term))))
(and (eq (plist-get term-entry :type) 'substitution)
org-glossary-display-substitute-value
`(mouse-face org-glossary-substitution-term
display
,(funcall
(if org-glossary-fontify-displayed-substitute
#'org-glossary--fontify-org-snippet #'identity)
(funcall
(if (string-match-p "^[[:upper:]][^[:upper:]]+$"
(match-string 0))
#'org-glossary--sentance-case #'identity)
(string-trim
(substring-no-properties
(org-element-interpret-data
(plist-get term-entry :value))))))))
`(help-echo
org-glossary--help-echo-from-textprop
mouse-face (:inverse-video t)