Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dynamic completion-ignored-extensions

0 views
Skip to first unread message

Kevin Ryde

unread,
Jul 17, 2008, 8:51:57 PM7/17/08
to help-gn...@gnu.org
Is there a way to have a kind of dynamic completion-ignored-extensions
so that for instance a .c file is ignored if there's a .xs of the same
name? Or even a kind of programmatic ignore so Makefile is not offered
if it seems to be in a build directory of some flavour (and therefore a
generated file).

I tried sticking a defadvice on file-name-completion, but in emacs22 it
doesn't seem to be reached. I guess read-file-name is C code and
bypasses advice, or something. Is there another filename reader that
could be could be easily pressed into service and customized?


Kevin Rodgers

unread,
Jul 20, 2008, 10:53:27 AM7/20/08
to help-gn...@gnu.org

Right, and read-file-name is implemented in C as well, which is why
there is the read-file-name-function variable (C-h v). Maybe something
like this will do what you want:

(defun my-read-file-name (&rest args)
"Tweak `completion-ignored-extensions' before calling `read-file-name'."
(let ((read-file-name-function nil)
(completion-ignored-extensions (your-code-here)))
(apply 'read-file-name args)))

(setq read-file-name-function 'my-read-file-name)

--
Kevin Rodgers
Denver, Colorado, USA

Kevin Ryde

unread,
Jul 23, 2008, 8:43:10 PM7/23/08
to help-gn...@gnu.org
Kevin Rodgers <kevin.d...@gmail.com> writes:
>
> (defun my-read-file-name (&rest args)
> "Tweak `completion-ignored-extensions' before calling `read-file-name'."
> (let ((read-file-name-function nil)
> (completion-ignored-extensions (your-code-here)))
> (apply 'read-file-name args)))

Yes, close, though I had the idea of ignores depending on the name
entered so-far too. I get some joy from munging deeper down like below.
I guess there's 3 or 4 other completion funcs too, but tab's the only
one I normally press. (I wouldn't be surprised if there was a cleaner
way too ...)


(defadvice minibuffer-complete (around my-ignore activate)
(if minibuffer-completing-file-name
(let ((completion-ignored-extensions completion-ignored-extensions))
(my-dynamic-ignored)
ad-do-it)
ad-do-it))

(defun my-dynamic-ignored ()
(let* ((contents (minibuffer-contents-no-properties))
(dir (file-name-directory contents)))

(if (file-expand-wildcards (concat contents "*.xs"))
(add-to-list 'completion-ignored-extensions ".c"))

(if (or (file-exists-p (concat dir "Makefile.am"))
(file-exists-p (concat dir "Makefile.PL")))
(add-to-list 'completion-ignored-extensions "Makefile"))

(if (file-exists-p (concat dir "Build.PL"))
(add-to-list 'completion-ignored-extensions "Build"))))


0 new messages