all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Restricting 'add-hook to a specific file extension
@ 2006-02-25 23:40 Tim Johnson
  2006-02-27 16:42 ` Kevin Rodgers
  0 siblings, 1 reply; 12+ messages in thread
From: Tim Johnson @ 2006-02-25 23:40 UTC (permalink / raw)


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? 

Thanks
tim

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* Re: Restricting 'add-hook to a specific file extension
       [not found] <mailman.5.1140910129.18076.help-gnu-emacs@gnu.org>
@ 2006-02-26  4:28 ` Barry Margolin
  2006-02-26 23:49   ` Tim Johnson
  2006-03-01 23:42 ` Nate Thern
  2006-03-05 21:38 ` Stefan Monnier
  2 siblings, 1 reply; 12+ messages in thread
From: Barry Margolin @ 2006-02-26  4:28 UTC (permalink / raw)


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 ***

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

* Re: Restricting 'add-hook to a specific file extension
  2006-02-26  4:28 ` Restricting 'add-hook to a specific file extension Barry Margolin
@ 2006-02-26 23:49   ` Tim Johnson
  2006-02-27  1:26     ` Barry Margolin
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Tim Johnson @ 2006-02-26 23:49 UTC (permalink / raw)


Hi Barry:

Yes, that works. Was just wondering if there was a way to use 'auto-load
itself......

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.
>


-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* Re: Restricting 'add-hook to a specific file extension
  2006-02-26 23:49   ` Tim Johnson
@ 2006-02-27  1:26     ` Barry Margolin
  2006-03-01 19:04     ` Kevin Rodgers
       [not found]     ` <mailman.125.1141286170.2835.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 12+ messages in thread
From: Barry Margolin @ 2006-02-27  1:26 UTC (permalink / raw)


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 ***

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

* Re: Restricting 'add-hook to a specific file extension
  2006-02-25 23:40 Tim Johnson
@ 2006-02-27 16:42 ` Kevin Rodgers
  0 siblings, 0 replies; 12+ messages in thread
From: Kevin Rodgers @ 2006-02-27 16:42 UTC (permalink / raw)


Tim Johnson 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? 

(add-hook 'scheme-mode-hook
           (lambda ()
             (when (string-match "\\.lsp\\'" buffer-file-name)
               ;; do something here
               )))

-- 
Kevin Rodgers

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

* Re: Restricting 'add-hook to a specific file extension
  2006-02-26 23:49   ` Tim Johnson
  2006-02-27  1:26     ` Barry Margolin
@ 2006-03-01 19:04     ` Kevin Rodgers
       [not found]     ` <mailman.125.1141286170.2835.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 12+ messages in thread
From: Kevin Rodgers @ 2006-03-01 19:04 UTC (permalink / raw)


Tim Johnson wrote:
 > 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

Here's a better way to match the file name:

(add-hook 'scheme-mode-hook
           (lambda ()
             (let ((case-fold-search nil))
               (if (string-match "\\.LSP\\'" buffer-file-name)
                   ;; code follows
                   ()
                 )))) ;; end 'add-hook

-- 
Kevin

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

* Re: Restricting 'add-hook to a specific file extension
       [not found] <mailman.5.1140910129.18076.help-gnu-emacs@gnu.org>
  2006-02-26  4:28 ` Restricting 'add-hook to a specific file extension Barry Margolin
@ 2006-03-01 23:42 ` Nate Thern
  2006-03-05 21:38 ` Stefan Monnier
  2 siblings, 0 replies; 12+ messages in thread
From: Nate Thern @ 2006-03-01 23:42 UTC (permalink / raw)


I'd like some help understanding this question (because I'm ignorant, 
not because it wasn't posed well). Tell me if this is correct:

1) newlisp-mode++ is a minor mode for use inside the major mode scheme-mode
2) (require 'newlisp-mode++) => loads newlisp-mode++ into memory
3) any time scheme-mode is the major mode, newlisp-mode++ will be an 
active minor mode (it's my understanding that minor modes do not 
generally behave this way - they have to be explicitely loaded or hooked)

If 3) is true, then it would be impossible to edit both file1.scm in 
scheme-mode only and file2.lsp in scheme-mode w/ newlisp-mode++, right? 
So I don't think 3) is true.

If 3) is not true then why wouldn't this work?:
(defun new-lisp+scheme-mode ()
    "Make scheme-mode the major mode and newlisp-mode++ a minor mode"
    (interactive "")
    (scheme-mode)
    (newlisp-mode++ 1))
(add-to-list 'auto-mode-alist '("\\.lsp$" . new-lisp+scheme-mode))

...

After thinking about it for a while, I think that newlisp-mode++ must be 
code which modifies the code of scheme-mode, so 1) is false.

So, what events is newlisp-mode++ hooking to, and why is a minor mode or 
derived mode not an option?


Tim Johnson 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? 
> 
> Thanks
> tim
> 

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

* Re: Restricting 'add-hook to a specific file extension
       [not found] <mailman.5.1140910129.18076.help-gnu-emacs@gnu.org>
  2006-02-26  4:28 ` Restricting 'add-hook to a specific file extension Barry Margolin
  2006-03-01 23:42 ` Nate Thern
@ 2006-03-05 21:38 ` Stefan Monnier
  2006-03-06  2:59   ` Tim Johnson
  2 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2006-03-05 21:38 UTC (permalink / raw)


> One solution is derived-mode, but I've had no luck with it.

Try harder.  No matter how hard it looks, it'll be easier than trying to fix
the problems you'll get with the other approach.


        Stefan

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

* Re: Restricting 'add-hook to a specific file extension
  2006-03-05 21:38 ` Stefan Monnier
@ 2006-03-06  2:59   ` Tim Johnson
  2006-03-06  8:41     ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Tim Johnson @ 2006-03-06  2:59 UTC (permalink / raw)


On 2006-03-05, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> One solution is derived-mode, but I've had no luck with it.
>
> Try harder.  No matter how hard it looks, it'll be easier than trying to fix
> the problems you'll get with the other approach.

 Stefan, I'm going to make you an offer, but first FYI:
 I code for a living, I've got 6 kids, 10 brother and sisters, aged
 parents and I belong to 2 churches. My R&D time is *very* limited.

 Your name is all over the place when I google keywords related to this
 topic, and I'm sure that you are an authority on this topic.

 So here's the offer: I'd *like* to create a derived-mode for the
 newlisp language, which is a lisp variant. I want it to be
 cross-compatible to Xemacs (which doesn't support
 font-lock-add-keywords).

 Give me a hand (via this newsgroup) and I will give you full credit for
 the results.

 I don't care about the credit. I just want to make it work.

 If you agree, and should you also think that this subject should expand
 to a tutorial, howto or wike component I will do the grunt work,
 documentation, whatever.
 
 I moved from vim to emacs a little over a year ago, I have found
 customizing for programming modes far more difficult than in vim and
 from my research in newsgroups and googling, I believe that I'm not the
 only one. 

 We could contribute significantly to the literature, methinks.
 Thanks
 tim

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* Re: Restricting 'add-hook to a specific file extension
       [not found]     ` <mailman.125.1141286170.2835.help-gnu-emacs@gnu.org>
@ 2006-03-06  2:59       ` Tim Johnson
  0 siblings, 0 replies; 12+ messages in thread
From: Tim Johnson @ 2006-03-06  2:59 UTC (permalink / raw)


On 2006-03-01, Kevin Rodgers <ihs_4664@yahoo.com> wrote:
> Tim Johnson wrote:
> Here's a better way to match the file name:
>
> (add-hook 'scheme-mode-hook
>            (lambda ()
>              (let ((case-fold-search nil))
>                (if (string-match "\\.LSP\\'" buffer-file-name)
>                    ;; code follows
>                    ()
>                  )))) ;; end 'add-hook
>

  You're right. This I will use.
  thanks!

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* Re: Restricting 'add-hook to a specific file extension
  2006-03-06  2:59   ` Tim Johnson
@ 2006-03-06  8:41     ` Stefan Monnier
  2006-03-06 17:59       ` Tim Johnson
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2006-03-06  8:41 UTC (permalink / raw)


>  So here's the offer: I'd *like* to create a derived-mode for the
>  newlisp language, which is a lisp variant. I want it to be
>  cross-compatible to Xemacs (which doesn't support
>  font-lock-add-keywords).

Post your current "solution" using add-hook.


        Stefan

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

* Re: Restricting 'add-hook to a specific file extension
  2006-03-06  8:41     ` Stefan Monnier
@ 2006-03-06 17:59       ` Tim Johnson
  0 siblings, 0 replies; 12+ messages in thread
From: Tim Johnson @ 2006-03-06 17:59 UTC (permalink / raw)


On 2006-03-06, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>  So here's the offer: I'd *like* to create a derived-mode for the
>>  newlisp language, which is a lisp variant. I want it to be
>>  cross-compatible to Xemacs (which doesn't support
>>  font-lock-add-keywords).
>
> Post your current "solution" using add-hook.
   
   I've started a new topic:
   See "Derived Mode 101 Howto"
   cheers
   tim

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

end of thread, other threads:[~2006-03-06 17:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.5.1140910129.18076.help-gnu-emacs@gnu.org>
2006-02-26  4:28 ` Restricting 'add-hook to a specific file extension Barry Margolin
2006-02-26 23:49   ` Tim Johnson
2006-02-27  1:26     ` Barry Margolin
2006-03-01 19:04     ` Kevin Rodgers
     [not found]     ` <mailman.125.1141286170.2835.help-gnu-emacs@gnu.org>
2006-03-06  2:59       ` Tim Johnson
2006-03-01 23:42 ` Nate Thern
2006-03-05 21:38 ` Stefan Monnier
2006-03-06  2:59   ` Tim Johnson
2006-03-06  8:41     ` Stefan Monnier
2006-03-06 17:59       ` Tim Johnson
2006-02-25 23:40 Tim Johnson
2006-02-27 16:42 ` Kevin Rodgers

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.