* Re: How to get hook var of the current major mode?
[not found] <mailman.17.1368841736.22516.help-gnu-emacs@gnu.org>
@ 2013-05-18 2:52 ` Emanuel Berg
0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2013-05-18 2:52 UTC (permalink / raw)
To: help-gnu-emacs
"netjunegg2@gmail.com" <netjunegg2@gmail.com> writes:
> I want to do somthing like this:
>
> (let ((hook (get--the--current--major--mode--hook)))
> (add-hook hook (lambda ()
> (setq truncate-lines t))))
I don't know, but if you want for lots of modes an easier way would be:
(set-default 'truncate-lines 1)
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 6+ messages in thread
* How to get hook var of the current major mode?
@ 2013-05-18 9:48 netjunegg2
2013-05-18 13:38 ` Dmitry Gutov
[not found] ` <mailman.32.1368884325.22516.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: netjunegg2 @ 2013-05-18 9:48 UTC (permalink / raw)
To: help-gnu-emacs
I want to do somthing like this:
(let ((hook (get--the--current--major--mode--hook)))
(add-hook hook (lambda ()
(setq truncate-lines t))))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get hook var of the current major mode?
2013-05-18 9:48 netjunegg2
@ 2013-05-18 13:38 ` Dmitry Gutov
2013-05-19 9:52 ` Jun
[not found] ` <mailman.32.1368884325.22516.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 6+ messages in thread
From: Dmitry Gutov @ 2013-05-18 13:38 UTC (permalink / raw)
To: netjunegg2@gmail.com; +Cc: help-gnu-emacs
"netjunegg2@gmail.com" <netjunegg2@gmail.com> writes:
> I want to do somthing like this:
> (let ((hook (get--the--current--major--mode--hook)))
> (add-hook hook (lambda ()
> (setq truncate-lines t))))
If the major mode is already current, then the hook has already run,
hasn't it? Adding a lambda to it will have to effect on the next buffer
in the same mode. And if the above form is run many times, each time a
new lambda will be added to the hook.
But anyway, try (intern (format "%s-hook" major-mode)).
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get hook var of the current major mode?
[not found] ` <mailman.32.1368884325.22516.help-gnu-emacs@gnu.org>
@ 2013-05-18 19:45 ` Emanuel Berg
2013-05-18 20:38 ` Dmitry Gutov
0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2013-05-18 19:45 UTC (permalink / raw)
To: help-gnu-emacs
Dmitry Gutov <dgutov@yandex.ru> writes:
>> I want to do somthing like this:
>> (let ((hook (get--the--current--major--mode--hook)))
>> (add-hook hook (lambda ()
>> (setq truncate-lines t))))
>
> ...And if the above form is run many times, each time a new lambda
> will be added to the hook.
When the hook fires, are all those lambda executed (doing the same
thing)?
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get hook var of the current major mode?
2013-05-18 19:45 ` Emanuel Berg
@ 2013-05-18 20:38 ` Dmitry Gutov
0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Gutov @ 2013-05-18 20:38 UTC (permalink / raw)
To: Emanuel Berg; +Cc: help-gnu-emacs
Emanuel Berg <embe8573@student.uu.se> writes:
> Dmitry Gutov <dgutov@yandex.ru> writes:
>
>>> I want to do somthing like this:
>>> (let ((hook (get--the--current--major--mode--hook)))
>>> (add-hook hook (lambda ()
>>> (setq truncate-lines t))))
>>
>> ...And if the above form is run many times, each time a new lambda
>> will be added to the hook.
>
> When the hook fires, are all those lambda executed (doing the same
> thing)?
Actually, sorry, I take that back. Even in lexical-binding environment,
(lambda () (abc)) is `equal' to another (lambda () (abc)), at least
currently. And `add-hook' checks if the given function is already
present in the list, with `member'. So there won't be duplicates in the
hook value.
Still, like I wrote previously, adding function to the hook of the
current major mode doesn't make much sense.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to get hook var of the current major mode?
2013-05-18 13:38 ` Dmitry Gutov
@ 2013-05-19 9:52 ` Jun
0 siblings, 0 replies; 6+ messages in thread
From: Jun @ 2013-05-19 9:52 UTC (permalink / raw)
To: Dmitry Gutov; +Cc: help-gnu-emacs
On 05/18/2013 01:38 PM, Dmitry Gutov wrote:
> "netjunegg2@gmail.com" <netjunegg2@gmail.com> writes:
>
>> I want to do somthing like this:
>> (let ((hook (get--the--current--major--mode--hook)))
>> (add-hook hook (lambda ()
>> (setq truncate-lines t))))
> If the major mode is already current, then the hook has already run,
> hasn't it? Adding a lambda to it will have to effect on the next buffer
> in the same mode. And if the above form is run many times, each time a
> new lambda will be added to the hook.
>
> But anyway, try (intern (format "%s-hook" major-mode)).
> .
>
This is what I want. In fact, I have defined a function which turns on
yasnippet minor mode, auto complete mode, etc, and a macro which can run
some code for all buffers in the same mode as the current. I want to
turn on some modes only when editing source code, not when viewing, and
not for buffers other than source code, which is not too usefull for
chinese.
Thank you.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-05-19 9:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.17.1368841736.22516.help-gnu-emacs@gnu.org>
2013-05-18 2:52 ` How to get hook var of the current major mode? Emanuel Berg
2013-05-18 9:48 netjunegg2
2013-05-18 13:38 ` Dmitry Gutov
2013-05-19 9:52 ` Jun
[not found] ` <mailman.32.1368884325.22516.help-gnu-emacs@gnu.org>
2013-05-18 19:45 ` Emanuel Berg
2013-05-18 20:38 ` Dmitry Gutov
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.