Compare commits

...

3 Commits

Author SHA1 Message Date
TEC 25fcf67e64
Make fontification compose better
No need to clobber existing faces.
2024-06-08 22:46:43 +08:00
TEC 3d37612603
Spelling/typo fixes in comments and docstrings 2024-06-08 22:46:43 +08:00
TEC 421c13f80d
Introduce new autodetect in headings customisation 2024-06-08 22:46:43 +08:00
3 changed files with 52 additions and 37 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,10 +83,10 @@ 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)
@ -94,6 +94,10 @@ If nil, they will be recognised anywhere in the document."
"Pick up on terms in plain text."
:type 'boolean)
(defcustom org-glossary-autodetect-in-headings nil
"Whether `org-glossary-automatic' should apply in headings."
:type 'boolean)
(defcustom org-glossary-plural-function #'org-glossary-english-plural
"A function which generates the plural form of a word."
:type 'function)
@ -110,7 +114,7 @@ grouping, and add the target type to the annotation instead."
:type 'boolean)
(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
@ -323,7 +327,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
@ -697,7 +701,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."
@ -724,7 +728,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.
@ -759,7 +763,8 @@ When KEEP-UNUSED is non-nil, unused terms will be included in the result."
element-context (org-element-context element-at-point)))
(cond
((or (org-glossary--within-definition-p element-context)
(eq 'headline (org-element-type element-at-point))
(and (not org-glossary-autodetect-in-headings)
(eq 'headline (org-element-type element-at-point)))
(and (eq 'keyword (org-element-type element-at-point))
(not (member (org-element-property :key element-at-point)
org-element-parsed-keywords))))
@ -1453,7 +1458,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)))
@ -1756,7 +1761,8 @@ This should only be run as an export hook."
(setq element-at-point (org-element-at-point)
element-context (org-element-context element-at-point))
(when (and (not exit)
(not (eq 'headline (org-element-type element-at-point)))
(not (and (not org-glossary-autodetect-in-headings)
(eq 'headline (org-element-type element-at-point))))
(memq 'link (org-element-restriction element-context))
(if (eq 'keyword (org-element-type element-at-point))
(member (org-element-property :key element-at-point)
@ -1791,30 +1797,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)

View File

@ -305,8 +305,10 @@ org-glossary-update-terms= first).
Note that as Org Glossary relies on links, recognised usages can only occur in
places where a link is appropriate (i.e. not inside a source block, verbatim
text, or another link, etc.). In addition terms in headings are ignored, as this
is considered broadly desirable.
text, or another link, etc.). The variable ~org-glossary-autodetect-in-headings~
determines whether terms in headings are automatically linked. By default, this
is off and headings are ignored, since this behaviour is generally seen as
undesirable.
In addition to all this, there's a bit of special behaviour for indexing. As
you can discuss a topic without explicitly stating it, we support

View File

@ -428,8 +428,10 @@ org-glossary-update-terms} first).
Note that as Org Glossary relies on links, recognised usages can only occur in
places where a link is appropriate (i.e. not inside a source block, verbatim
text, or another link, etc.). In addition terms in headings are ignored, as this
is considered broadly desirable.
text, or another link, etc.). The variable @code{org-glossary-autodetect-in-headings}
determines whether terms in headings are automatically linked. By default, this
is off and headings are ignored, since this behaviour is generally seen as
undesirable.
In addition to all this, there's a bit of special behaviour for indexing. As
you can discuss a topic without explicitly stating it, we support