branch: externals/denote commit 70e85ef34cd688a8fdfedd74ffec30f21e5342f5 Merge: 88de969826 c76b313352 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: GitHub <nore...@github.com>
Merge pull request #540 from frnsd/fix-sequence-prefix Fix false matches in 'denote-sequence-get-all-sequences-with-prefix' --- denote-sequence.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/denote-sequence.el b/denote-sequence.el index 40073a7500..858c311a0a 100644 --- a/denote-sequence.el +++ b/denote-sequence.el @@ -380,10 +380,18 @@ With optional SEQUENCES operate on those, else use the return value of `denote-sequence-get-all-sequences'. A sequence is a Denote signature that conforms with `denote-sequence-p'." - (seq-filter - (lambda (string) - (string-prefix-p sequence string)) - (or sequences (denote-sequence-get-all-sequences)))) + (let* ((prefix (denote-sequence-split sequence)) + (depth (length prefix))) + (seq-filter + (lambda (string) + (let ((value (denote-sequence-split string)) + (matched 0)) + (while (and value + (< matched depth) + (string-equal (pop value) (nth matched prefix))) + (setq matched (1+ matched))) + (= matched depth))) + (or sequences (denote-sequence-get-all-sequences))))) (defun denote-sequence-get-all-sequences-with-max-depth (depth &optional sequences) "Get sequences up to DEPTH (inclusive).