3

12.6 Tips for Defining Variables Robustly:

prefix--…’ : The variable is intended for internal use and is defined in the file prefix.el.

…-internal’ : The variable is intended for internal use and is defined in C code.

These variables that appear in "*Completions*" may not be helpful for most common Emacs users (and usually they don't have a docstring).

Any way to filter out them?


I tried this:

;; `*--*'
(setq completion-regexp-list '("^[^-]+\\($\\|-[^-]\\)"))

;; I don't know how to hide `*-internal'.

But Emacs signals an error Wrong type argument: stringp, nil whenever I type TAB among some characters, for example:

co-■-h

where ■ stands for a cursor.


emacs-version: 28.2
system-configuration: x86_64-w64-mingw32

shynur
  • 5,253
  • 1
  • 4
  • 25
  • Not only C-h v, but also several other such help-commands for common users, all provide these variables… – shynur Mar 15 '23 at 10:00

1 Answers1

1

1 What Regexp to Use

I don't know how to hide `*-internal'.

  • To Filter Out prefix--*:

    \`-?\([^-]+\(-[^-]+\)*-?\)?\'
    
  • To Filter Out *-internal:

    \(\(\`\|[^l]\)\|\(\`\|[^a]\)l\|\(\`\|[^n]\)al\|\(\`\|[^r]\)nal\|\(\`\|[^e]\)rnal\|\(\`\|[^t]\)ernal\|\(\`\|[^n]\)ternal\|\(\`\|[^i]\)nternal\|\(\`\|[^-]\)internal\)\'
    

2 How to Avoid that Error

But Emacs signals an error Wrong type argument: stringp, nil

I've reported this as bug#64351. In short, don't set it globally.

3 The Answer to the Question

Hide Variables for Internal Use in *Completions* when C-h v

shynur> I launched Emacs with “-Q” and evaluate:
shynur>
shynur> (advice-add 'describe-variable :around ;“C-h v”
shynur>             (lambda (advice-added-function &rest arguments)
shynur>               (let ((completion-regexp-list 
shynur>                      '("^\\([^-]*$\\|\\([^-]+\\(-[^-]+\\)-?\\)\\)$")))
shynur>                 (apply advice-added-function arguments))))
shynur>
shynur> to filter out symbols “*--*”.
shynur>
shynur> Then type “C-h v advice TAB”, I can still see some variables
shynur> whose names are “*--*” (e.g., “advice--bytecodes”).

Andreas> Interactive completion runs before the function is called, Andreas> inside call-interactively. You need to advice the Andreas> interactive spec.

shynur> Thanks! This is a tricky issue to me, because I only want to shynur> filter when calling “describe-variable”. I guess I have to shynur> give up this idea...

So

(let ((shynur--completion-regexp-list '("\\`-?\\([^-]+\\(-[^-]+\\)*-?\\)?\\'"
                                        "\\(\\(\\`\\|[^l]\\)\\|\\(\\`\\|[^a]\\)l\\|\\(\\`\\|[^n]\\)al\\|\\(\\`\\|[^r]\\)nal\\|\\(\\`\\|[^e]\\)rnal\\|\\(\\`\\|[^t]\\)ernal\\|\\(\\`\\|[^n]\\)ternal\\|\\(\\`\\|[^i]\\)nternal\\|\\(\\`\\|[^-]\\)internal\\)\\'"))
      (functions-for-completion [try-completion
                                 test-completion
                                 all-completions]))
  (seq-doseq (key ["C-h f"
                   "C-h v"])
    (let ((key-original-function (keymap-global-lookup key)))
      (global-set-key (kbd key) (lambda ()
                                  (interactive)
                                  (unwind-protect
                                      (progn
                                        (let ((completion-regexp-list+shynur--completion-regexp-list `(,@completion-regexp-list
                                                                                                       ,@shynur--completion-regexp-list)))
                                          (seq-doseq (funtion-for-completion functions-for-completion)
                                            (advice-add funtion-for-completion :around
                                                        (lambda (advised-function &rest arguments)
                                                          (let ((completion-regexp-list completion-regexp-list+shynur--completion-regexp-list))
                                                            (apply advised-function
                                                                   arguments))) '((name . "shynur--let-bind-completion-regexp-list")))))
                                        (call-interactively key-original-function))
                                    (seq-doseq (funtion-for-completion functions-for-completion)
                                      (advice-remove funtion-for-completion "shynur--let-bind-completion-regexp-list"))))))))
shynur
  • 5,253
  • 1
  • 4
  • 25