]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow 'completion-preview-require-minimum-symbol-length' to be nil
authorEshel Yaron <me@eshelyaron.com>
Wed, 5 Jun 2024 08:03:06 +0000 (10:03 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 5 Jun 2024 10:15:51 +0000 (12:15 +0200)
With some completion backends, completion preview is useful not only
after a partial symbol, but also after punctuation and other non-symbol
characters.  For example, in C code it's helpful to display the
completion preview for struct members when point is after 'foo->'.
Provide an option to skip the check for minimum symbol length at point
in order to support this use case.

* lisp/completion-preview.el
(completion-preview-minimum-symbol-length): Mention possible nil
value in type and docstring.
(completion-preview-require-minimum-symbol-length): Skip check
if 'completion-preview-minimum-symbol-length' is nil.

(cherry picked from commit c11fe940064724e5c41af20fdb0f60c49952f936)

lisp/completion-preview.el

index 119a969d38fbb75b3cd42e5b8281eca71fb3503c..64aba08ebbd6e8ab31ca352091688f816b3c28e1 100644 (file)
@@ -100,8 +100,12 @@ first candidate, and you can cycle between the candidates with
   :version "30.1")
 
 (defcustom completion-preview-minimum-symbol-length 3
-  "Minimum length of the symbol at point for showing completion preview."
-  :type 'natnum
+  "Minimum length of the symbol at point for showing completion preview.
+
+If this is nil rather than a number of characters, show the preview also
+after non-symbol characters, such as punctuation or whitespace."
+  :type '(choice (natnum :tag "Minimum number of symbol characters")
+                 (const :tag "Disable minimum symbol length requirement" nil))
   :version "30.1")
 
 (defcustom completion-preview-message-format
@@ -205,9 +209,10 @@ Completion Preview mode avoids updating the preview after these commands.")
 (defun completion-preview-require-minimum-symbol-length ()
   "Check if the length of symbol at point is at least above a certain threshold.
 `completion-preview-minimum-symbol-length' determines that threshold."
-  (let ((bounds (bounds-of-thing-at-point 'symbol)))
-    (and bounds (<= completion-preview-minimum-symbol-length
-                    (- (cdr bounds) (car bounds))))))
+  (or (null completion-preview-minimum-symbol-length)
+      (let ((bounds (bounds-of-thing-at-point 'symbol)))
+        (and bounds (<= completion-preview-minimum-symbol-length
+                        (- (cdr bounds) (car bounds)))))))
 
 (defun completion-preview-hide ()
   "Hide the completion preview."