all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Can one modify a variable definition in a major mode depending on buffer name?
@ 2016-07-30 12:54 Tom Browder
  2016-07-30 14:26 ` Emanuel Berg
  2016-07-30 17:37 ` Stefan Monnier
  0 siblings, 2 replies; 12+ messages in thread
From: Tom Browder @ 2016-07-30 12:54 UTC (permalink / raw
  To: help-gnu-emacs

I think I can do that, with some experimentation, but can anyone confirm
that it's reasonably possible?

My use case is modifying our perl6-mode for the slight difference in
allowable identifiers between Perl 6 and NQP (Not Quite Perl).  By
convention, nqp files end in ".nqp" so that the buffer name should be a
good way to automatically change the single regex bound to a var name in
the mode file.  That would save having to write another major mode just for
such a small change.

Thanks.

Best regards,

-Tom


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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 12:54 Can one modify a variable definition in a major mode depending on buffer name? Tom Browder
@ 2016-07-30 14:26 ` Emanuel Berg
  2016-07-30 16:22   ` Tom Browder
  2016-07-30 16:37   ` John Mastro
  2016-07-30 17:37 ` Stefan Monnier
  1 sibling, 2 replies; 12+ messages in thread
From: Emanuel Berg @ 2016-07-30 14:26 UTC (permalink / raw
  To: help-gnu-emacs

Tom Browder wrote:

> I think I can do that, with some
> experimentation, but can anyone confirm that
> it's reasonably possible?

;;; Perl
(defvar perl-propaganda)
(setq perl-propaganda "There's more than one way to do it!")

;; (setq perl-mode-hook nil)
(defun perl-mode-hook-f ()
  (let*((filename       (buffer-name))
        (filename-parts (split-string filename "\\."))
        (extention      (cadr filename-parts) ))
    (when (string-equal extention "nqp")
      (setq-local perl-propaganda "Do it today, in a different way!") )))
(add-hook 'perl-mode-hook #'perl-mode-hook-f)

(let ((modes (list
     '("\\.nqp\\'" . perl-mode)
     '("\\.tex\\'" . latex-mode)
     '("\\.php\\'" . html-mode)
     ;; etc.
    )))
  (setf auto-mode-alist (nconc modes auto-mode-alist)) )

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 64 Blogomatic articles -                   




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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 14:26 ` Emanuel Berg
@ 2016-07-30 16:22   ` Tom Browder
  2016-07-30 17:00     ` Emanuel Berg
  2016-07-30 16:37   ` John Mastro
  1 sibling, 1 reply; 12+ messages in thread
From: Tom Browder @ 2016-07-30 16:22 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

On Saturday, July 30, 2016, Emanuel Berg <embe8573@student.uu.se> wrote:

> Tom Browder wrote:
> > I think I can do that, with some
> > experimentation, but can anyone confirm that
> > it's reasonably possible?
>
> ;;; Perl
> (defvar perl-propaganda)


Thanks, Emanuel, for a working example.  I wasn't asking for a solution,
but it is appreciated.

Also, I love your choice of names!

I have to say this list is right up there with the Perl 6 lists for
friendliness and patience with noobs.  BTW, is there an irc channel for
elispers?

Thanks again, Emanuel!

Best regards,

-Tom


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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 14:26 ` Emanuel Berg
  2016-07-30 16:22   ` Tom Browder
@ 2016-07-30 16:37   ` John Mastro
  2016-07-30 17:33     ` Tom Browder
  1 sibling, 1 reply; 12+ messages in thread
From: John Mastro @ 2016-07-30 16:37 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

>   (let*((filename       (buffer-name))
>         (filename-parts (split-string filename "\\."))
>         (extention      (cadr filename-parts) ))
>     (when (string-equal extention "nqp")
>       (setq-local perl-propaganda "Do it today, in a different way!") )))

aka (when (string-match-p "\\.nqp\\'" (buffer-name)) ...)

        John



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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 16:22   ` Tom Browder
@ 2016-07-30 17:00     ` Emanuel Berg
  2016-07-30 17:28       ` Tom Browder
  0 siblings, 1 reply; 12+ messages in thread
From: Emanuel Berg @ 2016-07-30 17:00 UTC (permalink / raw
  To: help-gnu-emacs

Tom Browder wrote:

> is there an irc channel for elispers?

Ha ha - you old jester!

Check out how to set up ERC:

    http://user.it.uu.se/~embe8573/conf/emacs-init/erc-my.el

In particular:

    (setq erc-server "irc.freenode.net")
    (setq erc-port   6667)

Then

    /j emacs

I'm known as incal there but don't tell anyone
as it is probably against the rules to revel
one's true identity...

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 64 Blogomatic articles -                   




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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 17:00     ` Emanuel Berg
@ 2016-07-30 17:28       ` Tom Browder
  0 siblings, 0 replies; 12+ messages in thread
From: Tom Browder @ 2016-07-30 17:28 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

On Saturday, July 30, 2016, Emanuel Berg <embe8573@student.uu.se> wrote:

> Tom Browder wrote:
>
> > is there an irc channel for elispers?
>
> Ha ha - you old jester!
>
> Check out how to set up ERC:
>
>     http://user.it.uu.se/~embe8573/conf/emacs-init/erc-my.el


I just joined channel #mcmanny using irccloud and see the name 'incal' but
no one else at the moment, but I did announce myself and asked if any
elispers were about.

-Tom


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

* Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 16:37   ` John Mastro
@ 2016-07-30 17:33     ` Tom Browder
  0 siblings, 0 replies; 12+ messages in thread
From: Tom Browder @ 2016-07-30 17:33 UTC (permalink / raw
  To: John Mastro; +Cc: help-gnu-emacs@gnu.org

On Saturday, July 30, 2016, John Mastro <john.b.mastro@gmail.com
<javascript:_e(%7B%7D,'cvml','john.b.mastro@gmail.com');>> wrote:

> >   (let*((filename       (buffer-name))
> >         (filename-parts (split-string filename "\\."))
> >         (extention      (cadr filename-parts) ))
> >     (when (string-equal extention "nqp")
> >       (setq-local perl-propaganda "Do it today, in a different way!") )))
>
> aka (when (string-match-p "\\.nqp\\'" (buffer-name)) ...


Thanks, John. It seems like elisp has the same motto as Perl, i.e.,
"TIMTOWTDI."

Best,

-Tom


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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 12:54 Can one modify a variable definition in a major mode depending on buffer name? Tom Browder
  2016-07-30 14:26 ` Emanuel Berg
@ 2016-07-30 17:37 ` Stefan Monnier
  2016-07-30 17:48   ` Tom Browder
  2016-07-30 17:48   ` Tom Browder
  1 sibling, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2016-07-30 17:37 UTC (permalink / raw
  To: help-gnu-emacs

> My use case is modifying our perl6-mode for the slight difference in
> allowable identifiers between Perl 6 and NQP (Not Quite Perl).  By
> convention, nqp files end in ".nqp" so that the buffer name should be a
> good way to automatically change the single regex bound to a var name in
> the mode file.  That would save having to write another major mode just for
> such a small change.

    (add-to-list 'auto-mode-alist '("\\.nqp\\'" . nqp-mode))

    (define-derived-mode nqp-mode perl-mode "NQP"
      "Major mode for NQP's subset of Perl 6."
      (setq-local the-var-i-need-to-change the-new-value))


-- Stefan




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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 17:37 ` Stefan Monnier
@ 2016-07-30 17:48   ` Tom Browder
  2016-07-30 17:48   ` Tom Browder
  1 sibling, 0 replies; 12+ messages in thread
From: Tom Browder @ 2016-07-30 17:48 UTC (permalink / raw
  To: Stefan Monnier; +Cc: help-gnu-emacs@gnu.org

On Saturday, July 30, 2016, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> > My use case is modifying our perl6-mode for the slight difference in
> > allowable identifiers between Perl 6 and NQP (Not Quite Perl).  By

> convention, nqp files end in ".nqp" so that the buffer name should be a
> > good way to automatically change the single regex bound to a var name in
> > the mode file.  That would save having to write another major mode just
> for
> > such a small change.
>
>     (add-to-list 'auto-mode-alist '("\\.nqp\\'" . nqp-mode))
>
>     (define-derived-mode nqp-mode perl-mode "NQP"
>       "Major mode for NQP's subset of Perl 6."
>       (setq-local the-var-i-need-to-change the-new-value))


Stefan, are those lines the entire contents of a "nqp-mode.el" file?

-Tom


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

* Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 17:37 ` Stefan Monnier
  2016-07-30 17:48   ` Tom Browder
@ 2016-07-30 17:48   ` Tom Browder
  2016-08-02  1:28     ` Michael Heerdegen
  1 sibling, 1 reply; 12+ messages in thread
From: Tom Browder @ 2016-07-30 17:48 UTC (permalink / raw
  To: Stefan Monnier; +Cc: help-gnu-emacs@gnu.org

On Saturday, July 30, 2016, Stefan Monnier <monnier@iro.umontreal.ca
<javascript:_e(%7B%7D,'cvml','monnier@iro.umontreal.ca');>> wrote:

> > My use case is modifying our perl6-mode for the slight difference in
> > allowable identifiers between Perl 6 and NQP (Not Quite Perl).  By


> convention, nqp files end in ".nqp" so that the buffer name should be a
> > good way to automatically change the single regex bound to a var name in
> > the mode file.  That would save having to write another major mode just
> for
> > such a small change.
>
>     (add-to-list 'auto-mode-alist '("\\.nqp\\'" . nqp-mode))
>
>     (define-derived-mode nqp-mode perl-mode "NQP"
>       "Major mode for NQP's subset of Perl 6."
>       (setq-local the-var-i-need-to-change the-new-value))


Stefan, are those lines the entire contents of a "nqp-mode.el" file?

-Tom


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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-07-30 17:48   ` Tom Browder
@ 2016-08-02  1:28     ` Michael Heerdegen
  2016-08-02  1:35       ` Tom Browder
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Heerdegen @ 2016-08-02  1:28 UTC (permalink / raw
  To: Tom Browder; +Cc: help-gnu-emacs@gnu.org, Stefan Monnier

Tom Browder <tom.browder@gmail.com> writes:

> >     (add-to-list 'auto-mode-alist '("\\.nqp\\'" . nqp-mode))
> >
> >     (define-derived-mode nqp-mode perl-mode "NQP"
> >       "Major mode for NQP's subset of Perl 6."
> >       (setq-local the-var-i-need-to-change the-new-value))
>
>
> Stefan, are those lines the entire contents of a "nqp-mode.el" file?

[I'm not Stefan]

Yes, that should exactly do what you want.  It's more or less the
canonical solution for your problem (do you miss anything?).

Michael.



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

* Re: Can one modify a variable definition in a major mode depending on buffer name?
  2016-08-02  1:28     ` Michael Heerdegen
@ 2016-08-02  1:35       ` Tom Browder
  0 siblings, 0 replies; 12+ messages in thread
From: Tom Browder @ 2016-08-02  1:35 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: help-gnu-emacs@gnu.org, Stefan Monnier

On Monday, August 1, 2016, Michael Heerdegen <michael_heerdegen@web.de>
wrote:

> Tom Browder <tom.browder@gmail.com <javascript:;>> writes:
>
> > >     (add-to-list 'auto-mode-alist '("\\.nqp\\'" . nqp-mode))
> > >
> > >     (define-derived-mode nqp-mode perl-mode "NQP"
> > >       "Major mode for NQP's subset of Perl 6."
> > >       (setq-local the-var-i-need-to-change the-new-value))
> >
> >
> > Stefan, are those lines the entire contents of a "nqp-mode.el" file?
>
> [I'm not Stefan]
>
> Yes, that should exactly do what you want.  It's more or less the
> canonical solution for your problem (do you miss anything?).


Thanks, Michael.  The reason I asked if that was all is that often we see a
solution that is not exactly  "cookbook"  because it leaves out things that
make it complete.  I have not tried it yet but will tomorrow.

Best regards,

-Tom


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

end of thread, other threads:[~2016-08-02  1:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-30 12:54 Can one modify a variable definition in a major mode depending on buffer name? Tom Browder
2016-07-30 14:26 ` Emanuel Berg
2016-07-30 16:22   ` Tom Browder
2016-07-30 17:00     ` Emanuel Berg
2016-07-30 17:28       ` Tom Browder
2016-07-30 16:37   ` John Mastro
2016-07-30 17:33     ` Tom Browder
2016-07-30 17:37 ` Stefan Monnier
2016-07-30 17:48   ` Tom Browder
2016-07-30 17:48   ` Tom Browder
2016-08-02  1:28     ` Michael Heerdegen
2016-08-02  1:35       ` Tom Browder

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.