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

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

Re: How to automate file-opening (derived filename)?


From: Friedrich Dominicus
Subject: Re: How to automate file-opening (derived filename)?
Date: 09 Jan 2003 07:39:01 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Military Intelligence)

address@hidden (Danny Dorfman) writes:

> The thing is, there is no ONE header directory. There are several
> header directories, and it would be impractical to feed the directory
> every time I switch from one module to another. The macro must find
> the path automatically by doing some sort of "search & replace" on the
> full pathname (e.g. */src/* -> */inc/*) . I'm sorry, but I'm really
> bad at e-lisp, otherwise I would have changed your macro somehow to
> make it work for me...
Ok I suggest using an association list than.

(defvar *dir-match-alist*
  '(("~/programming/C/"
     . "~programming/C/")
    ("/some/path/" . "/some/path/include"))
  "Asscociation lisp which maps source pathes to 
appropriate header paths.")
 


(defun load-proper-header-file (&optional buf-name)
  (interactive)
  (let* ((src-dir (default-directory))
         (hdr-dir (cdr (assoc src-dir *dir-match-alist*)))
         (file-name (file-name-sans-extension 
                       (if buf-name buf-name (buffer-name)))))
    (find-file (concat hdr-dir file-name ".h"))))

This works as follows the first variable is a mapping from one path to
another (please do not forget to append the trailing / it should be a
dirctory. And you can read it like this:
All files in HOME/programming/C will find their header files in the
same directory all files in /some/path/ have their header files in
/some/path/include

The function load-proper-header-file works like this:
It tries to figure our in which directory it was called after that
it looks through the *dir-match-alist* association list for a matching
directory. assoc yield the whole line therefor we take the second
element (cdr), which it the directory path to the header files. After
that the file-name is build from the buffer name and in the end we
load the file which is the concatenation of the header directory part
the file name and ".h".

This works as intented, but is not very "user-friendly", but it's a
starting ground ...

Adding elements to the association list can be done with
push or acons

removing elements with remassoc


Regards
Friedrich




reply via email to

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