[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Restricting 'add-hook to a specific file extension
From: |
Barry Margolin |
Subject: |
Re: Restricting 'add-hook to a specific file extension |
Date: |
Sun, 26 Feb 2006 20:26:05 -0500 |
User-agent: |
MT-NewsWatcher/3.4 (PPC Mac OS X) |
In article <slrne04dpr.nla.tim@linus.johnson.com>,
Tim Johnson <tim@johnsons-web.com> wrote:
> Hi Barry:
>
> Yes, that works. Was just wondering if there was a way to use 'auto-load
> itself......
What does auto-load have to do with it -- that's just something that
happens the first time a function is used, to get the file loaded.
>
> Here's a snippet showing the conditional: (only slightly tested)
> (add-hook 'scheme-mode-hook
> (lambda ()
> (if (string-match ;; case insensitive
> ".LSP"
> (upcase(current-buffer-name)) ;; force upper case
> (- (length (current-buffer-name)) 4)) ;; end of name?
> ;; code follows
> ()
> ))) ;; end 'add-hook
>
> thanks
> tim
>
> On 2006-02-26, Barry Margolin <barmar@alum.mit.edu> wrote:
> > In article <mailman.5.1140910129.18076.help-gnu-emacs@gnu.org>,
> > Tim Johnson <tim@johnsons-web.com> wrote:
> >
> >> Is there a way to restrict 'add-hook to a specific file extension?
> >>
> >> Below is code from my .emacs:
> >>
> >> (require 'newlisp-mode++) ;; uses 'add-hook to extend 'scheme-mode
> >> (add-to-list 'auto-mode-alist '("\\.lsp\\'" . scheme-mode))
> >> (autoload 'scheme-mode "scheme" "Turn on scheme mode" t)
> >> (add-hook 'scheme-mode-hook 'turn-on-font-lock)
> >>
> >> I only want 'newlisp-mode++ to be used when the file extension is ".lsp".
> >> If
> >> the file extension is ".scm", I would want 'scheme-mode, but I would *not*
> >> want
> >> the code from 'newlisp-mode++ to take effect.
> >>
> >> One solution is derived-mode, but I've had no luck with it. For the time
> >> being
> >> (until I've had another 6 months or so of elisp under my belt), is there a
> >> way
> >> to restrict the add-hook action to only a file with a .lsp extension?
> >
> > Have the function you put in the hook check the filename suffix.
> >
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***