unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Friedrich Dominicus <frido@q-software-solutions.com>
Subject: Re: How to automate file-opening (derived filename)?
Date: 09 Jan 2003 07:39:01 +0100	[thread overview]
Message-ID: <87r8bm6d4q.fsf@fbigm.here> (raw)
In-Reply-To: 30055c1f.0301080505.26e1d8d2@posting.google.com

wildernesscat@hotmail.com (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	other threads:[~2003-01-09  6:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-07 14:52 How to automate file-opening (derived filename)? Danny Dorfman
2003-01-07 18:19 ` Friedrich Dominicus
2003-01-08  6:03   ` Alfred M. Szmidt
     [not found]   ` <mailman.53.1042007441.21513.help-gnu-emacs@gnu.org>
2003-01-08 11:54     ` Danny Dorfman
2003-01-11 12:49       ` Kai Großjohann
2003-01-08 13:05   ` Danny Dorfman
2003-01-09  6:39     ` Friedrich Dominicus [this message]
2003-01-09  6:44   ` Danny Dorfman
2003-01-09  8:06     ` Friedrich Dominicus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r8bm6d4q.fsf@fbigm.here \
    --to=frido@q-software-solutions.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).