help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use regexp with dir-locals-set-directory-class


From: Emanuel Berg
Subject: Re: Use regexp with dir-locals-set-directory-class
Date: Wed, 20 Aug 2014 19:05:40 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Florian Lindner <mailinglists@xgm.de> writes:

> can I use a regular expression (or globbing pattern)
> as DIRECTORY argument to
> dir-locals-set-directory-class and set a class for
> all directories that match?

Interesting question! Seems short answer is no, if you
check out the help:

    DIRECTORY is the name of a directory, a string.

But that of course doesn't mean you cannot have what
you want.

There should be many ways to do this. Perhaps even a
standard one?

The principle should be easy:

1. Apply the regexp on the set of possible directories,
   to get a list of matches.
2. Feed those one-by-one to the function.

Now, step one is the tricky part. I would use the shell
and ls. Like this:

(let*((dirs-str (with-temp-buffer
                  (call-process-shell-command
                   "ls -d testdir/*/" ; shell regexp here
                   nil ; no INFILE
                   t)  ; BUFFER (t -> current buffer = the temp one)
              (buffer-substring (point-min) (point-max)) ))
      (dirs (split-string dirs-str)) )
  (dolist (dir dirs)
    (dir-locals-set-directory-class dir 'class-one) ))
    
-- 
underground experts united


reply via email to

[Prev in Thread] Current Thread [Next in Thread]