* setting the mode of a buffer
@ 2014-03-07 0:10 lee
0 siblings, 0 replies; 8+ messages in thread
From: lee @ 2014-03-07 0:10 UTC (permalink / raw
To: help-gnu-emacs
Hi,
how would I set the mode of a buffer along the lines of ...
(with-current-buffer buffer (set-auto-mode t))
... but by setting a particular mode rather calling a function to set
modes which would be automatically set.
The above works, though it seems to be rather inefficient. I have tried
with (set-auto-mode-0) and got errors because a hook involved with the
mode I was trying to set couldn´t find its function.
In the end, what I´m trying to achieve is to be able to reload a mode
after it has been modified. To reload it, I´m using (unload-feature),
and that disables the mode for all buffers for which it is enabled. It
also magically removes an entry in auto-mode-alist for this mode.
When the mode is reloaded, I have to enable it for all relevant buffers
manually. To avoid having to do this, I´ve finally written a function
that goes through the buffer-list and enables the mode for particular
buffers. This function uses (set-auto-mode), in lack of a better
alternative.
Perhaps I´m going all wrong about this and there is a better way to
reload a mode?
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
[not found] <mailman.16657.1394156425.10748.help-gnu-emacs@gnu.org>
@ 2014-03-07 8:47 ` Joost Kremers
2014-03-07 11:28 ` lee
[not found] ` <mailman.16664.1394193871.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: Joost Kremers @ 2014-03-07 8:47 UTC (permalink / raw
To: help-gnu-emacs
lee wrote:
> Perhaps I´m going all wrong about this and there is a better way to
> reload a mode?
It's possible you don't need to reload the mode at all. This is Lisp,
after all, not C. If you change a function definition, you only need to
eval it (eval-defun, bound to C-M-x in emacs-lisp-mode), or you can
recompile the entire file.
If you change a defvar, eval'ing that won't load the new value, but you
can simply use setq to set the new value.
IME it's hardly never necessary to actually unload a feature and then
reload it.
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
2014-03-07 8:47 ` Joost Kremers
@ 2014-03-07 11:28 ` lee
[not found] ` <mailman.16664.1394193871.10748.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 8+ messages in thread
From: lee @ 2014-03-07 11:28 UTC (permalink / raw
To: help-gnu-emacs
Joost Kremers <joost.m.kremers@gmail.com> writes:
> lee wrote:
>> Perhaps I´m going all wrong about this and there is a better way to
>> reload a mode?
>
> It's possible you don't need to reload the mode at all. This is Lisp,
> after all, not C. If you change a function definition, you only need to
> eval it (eval-defun, bound to C-M-x in emacs-lisp-mode), or you can
> recompile the entire file.
>
> If you change a defvar, eval'ing that won't load the new value, but you
> can simply use setq to set the new value.
>
> IME it's hardly never necessary to actually unload a feature and then
> reload it.
The mode is byte-compiled --- it mainly provides some syntax
highlighting. Mostly, changes are to defcustoms to add another keyword
for the highlighting.
When I make a change, I byte-compile again. From there on, I need some
way to apply the changes. So far, I´ve been reloading the mode to
achieve this.
Are you saying that changes are magically applied by recompiling? Or
should I use 'M-x eval-defun my-mode' to apply them after recompiling?
And when I do so, wouldn´t emacs figure that it already knows the mode
because it´s already loaded and continue to use the previous version?
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
[not found] ` <mailman.16664.1394193871.10748.help-gnu-emacs@gnu.org>
@ 2014-03-12 22:19 ` Joost Kremers
2014-03-13 12:26 ` Stefan Monnier
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Joost Kremers @ 2014-03-12 22:19 UTC (permalink / raw
To: help-gnu-emacs
lee wrote:
> Joost Kremers <joost.m.kremers@gmail.com> writes:
> The mode is byte-compiled --- it mainly provides some syntax
> highlighting. Mostly, changes are to defcustoms to add another keyword
> for the highlighting.
Reevaluating a defcustom will normally reset the value of the variable,
so there's no need to unload and reload the file.
> When I make a change, I byte-compile again. From there on, I need some
> way to apply the changes. So far, I´ve been reloading the mode to
> achieve this.
Yes, but you do not need to unload it first. If you reload the file, the
new definitions will replace the old ones.
> Are you saying that changes are magically applied by recompiling? Or
> should I use 'M-x eval-defun my-mode' to apply them after recompiling?
> And when I do so, wouldn´t emacs figure that it already knows the mode
> because it´s already loaded and continue to use the previous version?
You do need to reload it, compiling alone is not enough.
IME defvar definitions aren't always updated when you reload a file, but
that's easily remedied with a setq in an *ielm* buffer. (Do `M-x ielm'
if you don't know about ielm. It's a god send.)
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
2014-03-12 22:19 ` Joost Kremers
@ 2014-03-13 12:26 ` Stefan Monnier
2014-03-15 21:12 ` lee
2014-03-15 21:09 ` lee
[not found] ` <mailman.17152.1394713615.10748.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2014-03-13 12:26 UTC (permalink / raw
To: help-gnu-emacs
> Reevaluating a defcustom will normally reset the value of the variable,
> so there's no need to unload and reload the file.
C-h f defcustom
[...]
:initialize
VALUE should be a function used to initialize the
variable. It takes two arguments, the symbol and value
given in the `defcustom' call. The default is
`custom-initialize-reset'.
[...]
C-h f custom-initialize-reset
[...]
The value is either the symbol's current value
(as obtained using the `:get' function), if any,
[...]
So, no, re-evaluating a defcustom will typically leave the variable at its
old value.
M-: (progn (defcustom sm-t 1 "hhaha") (defcustom sm-t 2 "hhaha") sm-t) RET
returns 1, not 2. IOW, it works more like defvar than like defconst.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
2014-03-12 22:19 ` Joost Kremers
2014-03-13 12:26 ` Stefan Monnier
@ 2014-03-15 21:09 ` lee
[not found] ` <mailman.17152.1394713615.10748.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 8+ messages in thread
From: lee @ 2014-03-15 21:09 UTC (permalink / raw
To: help-gnu-emacs
Joost Kremers <joost.m.kremers@gmail.com> writes:
> lee wrote:
> [...]
>> When I make a change, I byte-compile again. From there on, I need some
>> way to apply the changes. So far, I´ve been reloading the mode to
>> achieve this.
>
> Yes, but you do not need to unload it first. If you reload the file, the
> new definitions will replace the old ones.
>> Are you saying that changes are magically applied by recompiling? Or
>> should I use 'M-x eval-defun my-mode' to apply them after recompiling?
>> And when I do so, wouldn´t emacs figure that it already knows the mode
>> because it´s already loaded and continue to use the previous version?
>
> You do need to reload it, compiling alone is not enough.
Hm, yes, I have made another mode yesterday, and re-compiling and
reloading it and C-x C-e to redefine functions worked fine.
> IME defvar definitions aren't always updated when you reload a file, but
> that's easily remedied with a setq in an *ielm* buffer. (Do `M-x ielm'
> if you don't know about ielm. It's a god send.)
Wow, ielm is really good to know, thanks!
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
2014-03-13 12:26 ` Stefan Monnier
@ 2014-03-15 21:12 ` lee
0 siblings, 0 replies; 8+ messages in thread
From: lee @ 2014-03-15 21:12 UTC (permalink / raw
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Reevaluating a defcustom will normally reset the value of the variable,
>> so there's no need to unload and reload the file.
>
> C-h f defcustom
>
> [...]
> :initialize
> VALUE should be a function used to initialize the
> variable. It takes two arguments, the symbol and value
> given in the `defcustom' call. The default is
> `custom-initialize-reset'.
> [...]
>
> C-h f custom-initialize-reset
>
> [...]
> The value is either the symbol's current value
> (as obtained using the `:get' function), if any,
> [...]
>
> So, no, re-evaluating a defcustom will typically leave the variable at its
> old value.
>
> M-: (progn (defcustom sm-t 1 "hhaha") (defcustom sm-t 2 "hhaha") sm-t) RET
>
> returns 1, not 2. IOW, it works more like defvar than like defconst.
Awesome --- it means I just have to do it right and use functions to set
up things and don`t need to unload the mode anymore :)
I got this mode from somewhere quite a while ago, and I think it isn`t
done right. There isn`t anything to disable it, either.
--
Knowledge is volatile and fluid. Software is power.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: setting the mode of a buffer
[not found] ` <mailman.17152.1394713615.10748.help-gnu-emacs@gnu.org>
@ 2014-03-17 11:17 ` Joost Kremers
0 siblings, 0 replies; 8+ messages in thread
From: Joost Kremers @ 2014-03-17 11:17 UTC (permalink / raw
To: help-gnu-emacs
Stefan Monnier wrote:
> So, no, re-evaluating a defcustom will typically leave the variable at its
> old value.
Sorry, I should have mentioned that I meant reevaluating the defcustom
with C-M-x (`eval-defun'). Other methods (including reloading the file)
indeed do not.
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-03-17 11:17 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-07 0:10 setting the mode of a buffer lee
[not found] <mailman.16657.1394156425.10748.help-gnu-emacs@gnu.org>
2014-03-07 8:47 ` Joost Kremers
2014-03-07 11:28 ` lee
[not found] ` <mailman.16664.1394193871.10748.help-gnu-emacs@gnu.org>
2014-03-12 22:19 ` Joost Kremers
2014-03-13 12:26 ` Stefan Monnier
2014-03-15 21:12 ` lee
2014-03-15 21:09 ` lee
[not found] ` <mailman.17152.1394713615.10748.help-gnu-emacs@gnu.org>
2014-03-17 11:17 ` Joost Kremers
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.