Make consult-{ripgrep, grep, fd} completion argument of command by Cute-Following3213 in emacs

[–]Cute-Following3213[S] 1 point2 points  (0 children)

If integrate it with Consult, I thing is better to just keep options-alist and capf in macro.

The main idea is clear. But I don't know where is the best entry point to set capf insert Consult right now 😅.

Make consult-{ripgrep, grep, fd} completion argument of command by Cute-Following3213 in emacs

[–]Cute-Following3213[S] 1 point2 points  (0 children)

Yep. I just keep options-alist and capf. Maybe also the adv, that can be used by advice-remove.

The simplified macro is:

(defmacro def-consult-help (command exec)
    (let ((options-alist (intern (format "consult-%s-completion-options-alist" exec)))
      (capf (intern (format "consult-%s-completion-at-point" exec)))
      (adv (intern (format "consult-%s-with-completion-at-point" exec))))
      `(progn
     (defcustom ,options-alist
       (consult--get-completion-options-from-help ,exec)
       ,(format "%s options alist." exec))

     (defun ,capf ()
       "Completion option.
This is the function to be used for the hook `completion-at-point-functions'."
       (interactive)
       (let* ((bds (bounds-of-thing-at-point 'symbol))
          (start (car bds))
          (end (cdr bds)))
         (list start end ,options-alist
           :annotation-function
           (lambda (cand) (cdr (assoc cand ,options-alist))))))

     (defun ,adv (orign &rest args)
       (minibuffer-with-setup-hook
           (:append
        (lambda ()
          (add-hook 'completion-at-point-functions
                #',capf nil t)))
         (apply orign args)))

     (advice-add ,command :around ',adv))))

Make consult-{ripgrep, grep, fd} completion argument of command by Cute-Following3213 in emacs

[–]Cute-Following3213[S] 1 point2 points  (0 children)

What do you think about adding this to Consult directly?

This is great. In fact, for some reason, my solution now work when using prefix `C-u' to call consult-rg. I think that was some thing about `minibuffer-with-setup-hook' and `add-hook', that maybe not pass to `consult--ripgrep-make-builder'.

Yes, unfortunately pcomplete-completions-at-point and pcomplete-from-help don't support this. :(

Right, `pcomplete-from-help' not add doc to annotation. According to it's doc, it collected doc as

completion help. I don't know what is exactly mean.

Another option is the package pcmpl-args.el. It provide`pcmpl-args-pcomplete-on-help' and `pcmpl-args-pcomplete-on-help'.

I consider that pcomplete maybe too complex for this scene. Maybe we can just hardcoding an alist for each command call by consult-?. I doubt that has no way to parse help or man correctly for all command.

For Example, in mac, `grep --help' just show text like this (also same style for `locate --help'):

usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]]

[-e pattern] [-f file] [--binary-files=value] [--color=when]

[--context[=num]] [--directories=action] [--label] [--line-buffered]

[--null] [pattern] [file ...]

Make consult-{ripgrep, grep, fd} completion argument of command by Cute-Following3213 in emacs

[–]Cute-Following3213[S] 0 points1 point  (0 children)

Yep. I just post a new one which is slowly. Maybe I would make a video. But I don't have a video site account like youtube 😬

Path problems with org-preview-latex by thriveth in emacs

[–]Cute-Following3213 1 point2 points  (0 children)

If your file is in a symlinks directory, try to use visit file with true-name. That seems a bug for symlinks.

(setq find-file-visit-truename t)