]> git.eshelyaron.com Git - emacs.git/commitdiff
crm.el: Workaround issue with nil completion table
authorEshel Yaron <me@eshelyaron.com>
Tue, 23 Jul 2024 19:22:29 +0000 (21:22 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 23 Jul 2024 19:22:29 +0000 (21:22 +0200)
lisp/emacs-lisp/crm.el

index ca98d640a5eb944770bf2ebc192bd69dd6e52ef9..c6e40d6fa2769072c52babf60e8f4af5857daeec 100644 (file)
@@ -385,9 +385,15 @@ that fails this command prompts you for the separator to use."
          (cons 'metadata
                (cons (cons 'adjust-base-function
                            (lambda (base)
-                             (funcall (or (alist-get 'adjust-base-function md)
-                                          #'identity)
-                                      (substring base beg))))
+                             ;; When TABLE is nil and point is after
+                             ;; separator, we may get empty `base' from
+                             ;; `completion-all-sorted-completions',
+                             ;; because `completion-all-completions'
+                             ;; returns nil with no base length.
+                             (if (string-empty-p base) base
+                               (funcall (or (alist-get 'adjust-base-function md)
+                                            #'identity)
+                                        (substring base beg)))))
                      (cdr-safe md)))))
       ('nil (let ((comp (complete-with-action a table (substring s beg) p)))
               (if (stringp comp) (concat (substring s 0 beg) comp) comp)))