From ae533fa3093a1fca2217c2e3e2d7d12d23122d2b Mon Sep 17 00:00:00 2001 From: Philippe Crama Date: Tue, 23 Nov 2021 14:33:47 +0100 Subject: [PATCH] (fix)node: fix org-roam-node-slug compatibility with Emacs 29.1 (#1982) Emacs commit 3f096eb3405b2fce7c35366eb2dcf025dda55783 introduced `string-glyph-compose` and `string-glyph-decompose`, autoloading these instead of the (still existing) `ucs-normalize-NFC-region` and `ucs-normalize-NFD-region`. There are three cases: - Emacs where these transitions have not happened yet (e.g. 27.1): `ucs-normalize-NFC-region` and `ucs-normalize-NFD-region` are still autoloaded, aliasing the new names to them will keep them usable and the code still works. - Emacs where the new functions are defined (not yet released): the new names are autoloaded, no aliases are installed and the code still works. - A (hypothetical?) Emacs where `string-glyph-compose` and `string-glyph-decompose` are renamed. If `ucs-normalize-NFC-region` and `ucs-normalize-NFD-region` do not get their autoloaded status back, the aliasing will happen but the functions not autoloaded and the code will break in the same way as in #1981 --- org-roam-node.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/org-roam-node.el b/org-roam-node.el index d65ebce..abbd44d 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -150,6 +150,17 @@ It takes a single argument REF, which is a propertized string." id level point todo priority scheduled deadline title properties olp tags aliases refs) +;; Shim `string-glyph-compose' and `string-glyph-decompose' for Emacs versions that do not have it. +;; The functions were introduced in emacs commit 3f096eb3405b2fce7c35366eb2dcf025dda55783 and the +;; (original) functions behind them aren't autoloaded anymore. +(dolist (sym.replace + '((string-glyph-compose . ucs-normalize-NFC-region) + (string-glyph-decompose . ucs-normalize-NFD-region))) + (let ((emacs-29-symbol (car sym.replace)) + (previous-implementation (cdr sym.replace))) + (unless (fboundp emacs-29-symbol) + (defalias emacs-29-symbol previous-implementation)))) + (cl-defmethod org-roam-node-slug ((node org-roam-node)) "Return the slug of NODE." (let ((title (org-roam-node-title node)) @@ -178,9 +189,9 @@ It takes a single argument REF, which is a propertized string." (cl-flet* ((nonspacing-mark-p (char) (memq char slug-trim-chars)) (strip-nonspacing-marks (s) - (ucs-normalize-NFC-string + (string-glyph-compose (apply #'string (seq-remove #'nonspacing-mark-p - (ucs-normalize-NFD-string s))))) + (string-glyph-decompose s))))) (cl-replace (title pair) (replace-regexp-in-string (car pair) (cdr pair) title))) (let* ((pairs `(("[^[:alnum:][:digit:]]" . "_") ;; convert anything not alphanumeric