all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* dynamic completion-ignored-extensions
@ 2008-07-18  0:51 Kevin Ryde
  2008-07-20 14:53 ` Kevin Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Ryde @ 2008-07-18  0:51 UTC (permalink / raw)
  To: help-gnu-emacs

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?




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dynamic completion-ignored-extensions
  2008-07-18  0:51 dynamic completion-ignored-extensions Kevin Ryde
@ 2008-07-20 14:53 ` Kevin Rodgers
  2008-07-24  0:43   ` Kevin Ryde
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Rodgers @ 2008-07-20 14:53 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Ryde wrote:
> 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?

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dynamic completion-ignored-extensions
  2008-07-20 14:53 ` Kevin Rodgers
@ 2008-07-24  0:43   ` Kevin Ryde
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Ryde @ 2008-07-24  0:43 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Rodgers <kevin.d.rodgers@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"))))




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-07-24  0:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18  0:51 dynamic completion-ignored-extensions Kevin Ryde
2008-07-20 14:53 ` Kevin Rodgers
2008-07-24  0:43   ` Kevin Ryde

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.