unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* add-hook
@ 2007-06-06 11:26 Sebastian Tennant
  2007-06-07  0:20 ` add-hook Sebastian Tennant
       [not found] ` <mailman.1696.1181175524.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 20+ messages in thread
From: Sebastian Tennant @ 2007-06-06 11:26 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

Am I right in thinking this is OK:

(add-hook 'foo-hook 'bar-function 'baz-function ...)

And this is OK:

(add-hook 'foo-hook (lambda () ...))

But this is not:

(add-hook 'foo-hook 'bar-function (lambda () ...))

That is to say, single functions passed via add-hook are added to a
list the contents of which are evaluated in turn, but a lambda
function passed via add-hook is evaluated as it stands, (no list of
functions is created) so there can be only one lambda function passed
via add-hook at any one time?

Sebastian

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

* Re: add-hook
       [not found] <mailman.1634.1181129906.32220.help-gnu-emacs@gnu.org>
@ 2007-06-06 12:04 ` Katsumi Yamaoka
  2007-06-06 20:41 ` add-hook Robert D. Crawford
  1 sibling, 0 replies; 20+ messages in thread
From: Katsumi Yamaoka @ 2007-06-06 12:04 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> In <mailman.1634.1181129906.32220.help-gnu-emacs@gnu.org>
>>>>>	Sebastian Tennant wrote:

> Am I right in thinking this is OK:

> (add-hook 'foo-hook 'bar-function 'baz-function ...)

`C-h f add-hook RET' says:

(add-hook HOOK FUNCTION &optional APPEND LOCAL)

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

* Re: add-hook
       [not found] <mailman.1634.1181129906.32220.help-gnu-emacs@gnu.org>
  2007-06-06 12:04 ` add-hook Katsumi Yamaoka
@ 2007-06-06 20:41 ` Robert D. Crawford
  1 sibling, 0 replies; 20+ messages in thread
From: Robert D. Crawford @ 2007-06-06 20:41 UTC (permalink / raw)
  To: help-gnu-emacs

Sebastian Tennant <sebyte@smolny.plus.com> writes:

> Am I right in thinking this is OK:
>
> (add-hook 'foo-hook 'bar-function 'baz-function ...)

As I understand it, no.  Only one function can be added to a hook at a
time.  This is what the lambda is for.  In effect it creates a single
function from multiple functions when only one function can be used.
For example:

(add-hook 'emacs-lisp-mode-hook
	  '(lambda ()
	     (make-local-hook 'after-save-hook)
	     (add-hook 'after-save-hook
		       '(lambda ()
			  (byte-compile-file buffer-file-name)) 
		       nil t)))


Everything contained within the lambda on line 2 is considered one
item.  

> That is to say, single functions passed via add-hook are added to a
> list the contents of which are evaluated in turn, but a lambda
> function passed via add-hook is evaluated as it stands, (no list of
> functions is created) so there can be only one lambda function passed
> via add-hook at any one time?

I am not sure what exactly you mean here.  I _think_ you can run
add-hook multiple times for the same hook in the same file using lambda
each time, as inefficient as it may be.

I hope this answers your questions,
rdc
-- 
Robert D. Crawford                                      rdc1x@comcast.net

BOFH excuse #351:

PEBKAC (Problem Exists Between Keyboard And Chair)

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

* Re: add-hook
  2007-06-06 11:26 add-hook Sebastian Tennant
@ 2007-06-07  0:20 ` Sebastian Tennant
       [not found] ` <mailman.1696.1181175524.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 20+ messages in thread
From: Sebastian Tennant @ 2007-06-07  0:20 UTC (permalink / raw)
  To: help-gnu-emacs

It was a rushed, and poorly thought out question.  There are a number
of simple tests I should have perfomed first, but sometimes... well,
call it laziness perhaps...

C-h f add-hook:

  add-hook is a compiled Lisp function in `subr.el'.
  (add-hook HOOK FUNCTION &optional APPEND LOCAL)

  [...]

  HOOK should be a symbol, and FUNCTION may be any valid function.  If
  HOOK is void, it is first set to nil.  If HOOK's value is a single
  function, it is changed to a list of functions.
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As I read it now, I realise it is hook's _value_ that is changed to a
list of functions, not FUNCTIONS's value...

Would it not be clearer if it read, "If HOOK's _existing_ value..."?

At first I read it to mean FUNCTION's value was changed to a list of
functions... confusion all round!

Another point:

  Quoth "Robert D. Crawford" <rdc1x@comcast.net>:
  > For example:

  > (add-hook 'emacs-lisp-mode-hook
  > 	  '(lambda ()
  >          ...

I understand that lambda functions allow you to pass a number of
functions in a single FUNCTION, but I think you'll find lambda
functions don't need to be quoted.

This fact, and the fact that symbols representing funtions _do_ need
to be quoted, only added to my 'list of functions versus single
function' misconception.

Perhaps someone could explain why it is lambda functions don't need to
be quoted in this context?

Sebastian

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

* Re: add-hook
       [not found] ` <mailman.1696.1181175524.32220.help-gnu-emacs@gnu.org>
@ 2007-06-07  7:16   ` Thien-Thi Nguyen
  2007-06-07 10:00     ` add-hook Sebastian Tennant
       [not found]     ` <mailman.1711.1181210337.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 20+ messages in thread
From: Thien-Thi Nguyen @ 2007-06-07  7:16 UTC (permalink / raw)
  To: help-gnu-emacs

() Sebastian Tennant <sebyte@smolny.plus.com>
() Thu, 07 Jun 2007 03:20:33 +0300

   Perhaps someone could explain why it is lambda
   functions don't need to be quoted in this context?

in elisp, the form `(lambda ARGS BODY)' is self-quoting in
all contexts, like numbers and strings.  sometimes you see:

 (function (lambda ...))
 #'(lambda ...)

these serve as hints to the byte compiler that the form
should be compiled.  on the other hand, if you see:

 '(lambda ...)

then that tells the compiler to treat the form as data (DON'T compile).
if you aren't byte compiling, quoting is strictly optional.

thi

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

* Re: add-hook
  2007-06-07  7:16   ` add-hook Thien-Thi Nguyen
@ 2007-06-07 10:00     ` Sebastian Tennant
       [not found]     ` <mailman.1711.1181210337.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 20+ messages in thread
From: Sebastian Tennant @ 2007-06-07 10:00 UTC (permalink / raw)
  To: help-gnu-emacs

Quoth Thien-Thi Nguyen <ttn@gnuvola.org>:
> () Sebastian Tennant <sebyte@smolny.plus.com>
> () Thu, 07 Jun 2007 03:20:33 +0300
>
>    Perhaps someone could explain why it is lambda
>    functions don't need to be quoted in this context?
>
> in elisp, the form `(lambda ARGS BODY)' is self-quoting in
> all contexts, like numbers and strings.  sometimes you see:
>
>  (function (lambda ...))
>  #'(lambda ...)
>
> these serve as hints to the byte compiler that the form
> should be compiled.  on the other hand, if you see:
>
>  '(lambda ...)
>
> then that tells the compiler to treat the form as data (DON'T compile).
> if you aren't byte compiling, quoting is strictly optional.
>
> thi

Many thanks.

I was aware that everything boils down to lambda functions in lisp but
it hadn't occured to me that they are self quoting in all contexts,
although now I think about it I realise they _have_ to be
self-quoting, given that they are one of the fundamental building
blocks...

(info "(elisp)Anonymous Functions"):

  In Lisp, a function is a list that starts with `lambda', a byte-code
  function compiled from such a list, or alternatively a primitive
  subr-object; names are "extra."

Sebastian

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

* Re: add-hook
       [not found]     ` <mailman.1711.1181210337.32220.help-gnu-emacs@gnu.org>
@ 2007-06-07 14:01       ` Thien-Thi Nguyen
  0 siblings, 0 replies; 20+ messages in thread
From: Thien-Thi Nguyen @ 2007-06-07 14:01 UTC (permalink / raw)
  To: help-gnu-emacs

() Sebastian Tennant <sebyte@smolny.plus.com>
() Thu, 07 Jun 2007 13:00:44 +0300

   (info "(elisp)Anonymous Functions"):

     In Lisp, a function is a list that starts with `lambda', a byte-code
     function compiled from such a list, or alternatively a primitive
     subr-object; names are "extra."

you can test this in *scratch*:

((lambda (n) (+ n (* n n))) 6)

(funcall (byte-compile (lambda (n) (+ n (* n n)))) 6)

thi

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

* add-hook
@ 2011-06-04 13:00 daniele.g
  2011-06-04 14:11 ` add-hook Teemu Likonen
  0 siblings, 1 reply; 20+ messages in thread
From: daniele.g @ 2011-06-04 13:00 UTC (permalink / raw)
  To: help-gnu-emacs

Is that syntax correct?

--8<---------------cut here---------------start------------->8---
(add-hook 'c-mode-common-hook
	  '(lambda ()
	     'hs-minor-mode
	     'linum-mode
	     (local-set-key [(control return)] 
			    'semantic-ia-complete-symbol-menu)))
--8<---------------cut here---------------end--------------->8---

-- 
        "Come va?".
        "Bene, grazie.  E tu?".
        "Medio".  Cosi' diceva sempre.
        		-- Enrico Brizzi, Jack Frusciante e' uscito dal gruppo




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

* Re: add-hook
  2011-06-04 13:00 add-hook daniele.g
@ 2011-06-04 14:11 ` Teemu Likonen
  2011-06-04 18:35   ` add-hook daniele.g
  0 siblings, 1 reply; 20+ messages in thread
From: Teemu Likonen @ 2011-06-04 14:11 UTC (permalink / raw)
  To: daniele g.; +Cc: help-gnu-emacs

* 2011-06-04T15:00:46+02:00 * daniele g. wrote:

> Is that syntax correct?
>
>
> (add-hook 'c-mode-common-hook
> 	  '(lambda ()
> 	     'hs-minor-mode
> 	     'linum-mode
> 	     (local-set-key [(control return)] 
> 			    'semantic-ia-complete-symbol-menu)))

It is correct Emacs Lisp syntax but most likely the behaviour is not
what you want. I believe you want this:


    (add-hook 'c-mode-common-hook
              (lambda ()
                (hs-minor-mode 1)
                (linum-mode 1)
                (local-set-key [(control return)] 
                               'semantic-ia-complete-symbol-menu)))



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

* Re: add-hook
  2011-06-04 14:11 ` add-hook Teemu Likonen
@ 2011-06-04 18:35   ` daniele.g
  2011-06-05 10:58     ` add-hook Richard Riley
  0 siblings, 1 reply; 20+ messages in thread
From: daniele.g @ 2011-06-04 18:35 UTC (permalink / raw)
  To: help-gnu-emacs

Teemu Likonen <tlikonen@iki.fi> writes:

>     (Add-hook 'c-mode-common-hook
>               (lambda ()
>                 (hs-minor-mode 1)
>                 (linum-mode 1)
>                 (local-set-key [(control return)] 
>                                'semantic-ia-complete-symbol-menu)))

You read my mind.
-- 
           This signature was automatically generated with
           Signify v1.14.  For this and other cool products,
           check out http://www.debian.org/




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

* Re: add-hook
  2011-06-04 18:35   ` add-hook daniele.g
@ 2011-06-05 10:58     ` Richard Riley
  2011-06-05 18:58       ` add-hook daniele.g
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Riley @ 2011-06-05 10:58 UTC (permalink / raw)
  To: help-gnu-emacs

dgiglio@iol.it (daniele.g) writes:

> Teemu Likonen <tlikonen@iki.fi> writes:
>
>>     (Add-hook 'c-mode-common-hook
>>               (lambda ()
>>                 (hs-minor-mode 1)
>>                 (linum-mode 1)
>>                 (local-set-key [(control return)] 
>>                                'semantic-ia-complete-symbol-menu)))
>
> You read my mind.

I think I mentioned it before, but auto-complete has an excellent
completion mechanism which you can share/use across all modes for
consistency and you can easily set the completion sources to use the
semantic completion candidates in addition to the more common sources
like dabbrev.

To wet your whistle, look here

http://cx4a.org/software/auto-complete/


regards

r.



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

* Re: add-hook
  2011-06-05 10:58     ` add-hook Richard Riley
@ 2011-06-05 18:58       ` daniele.g
  2011-06-05 20:26         ` add-hook Richard Riley
  0 siblings, 1 reply; 20+ messages in thread
From: daniele.g @ 2011-06-05 18:58 UTC (permalink / raw)
  To: help-gnu-emacs

Richard Riley <rileyrg@googlemail.com> writes:

> I think I mentioned it before, but auto-complete has an excellent
> completion mechanism which you can share/use across all modes for
> consistency and you can easily set the completion sources to use the
> semantic completion candidates in addition to the more common sources
> like dabbrev.

Yes, you did. But it seems it doesn't work as it promises. It seems it
autompletes symbols only in a per session way (every time I start
editing a new file it resets all the simbols previously gathered), and,
what it's worst, its scope is limited on the open buffer, it doesn't
look for in included headers.

But maybe it's only my emacs that is misconfigured.






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

* Re: add-hook
  2011-06-05 18:58       ` add-hook daniele.g
@ 2011-06-05 20:26         ` Richard Riley
  2011-06-05 22:28           ` add-hook daniele.g
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Riley @ 2011-06-05 20:26 UTC (permalink / raw)
  To: help-gnu-emacs

dgiglio@iol.it (daniele.g) writes:

> Richard Riley <rileyrg@googlemail.com> writes:
>
>> I think I mentioned it before, but auto-complete has an excellent
>> completion mechanism which you can share/use across all modes for
>> consistency and you can easily set the completion sources to use the
>> semantic completion candidates in addition to the more common sources
>> like dabbrev.
>
> Yes, you did. But it seems it doesn't work as it promises. It seems it
> autompletes symbols only in a per session way (every time I start
> editing a new file it resets all the simbols previously gathered),
> and,

What gathered symbols does semantic maintain?

> what it's worst, its scope is limited on the open buffer, it doesn't
> look for in included headers.
>
> But maybe it's only my emacs that is misconfigured.

I suspect it is.

As I said, it can use the semantic back end completion sets.





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

* Re: add-hook
  2011-06-05 20:26         ` add-hook Richard Riley
@ 2011-06-05 22:28           ` daniele.g
  2011-06-05 23:33             ` add-hook Richard Riley
  0 siblings, 1 reply; 20+ messages in thread
From: daniele.g @ 2011-06-05 22:28 UTC (permalink / raw)
  To: help-gnu-emacs

Richard Riley <rileyrg@googlemail.com> writes:

> Dgiglio@iol.it (daniele.g) writes:
>
>> Richard Riley <rileyrg@googlemail.com> writes:
>>
>>> I think I mentioned it before, but auto-complete has an excellent
>>> completion mechanism which you can share/use across all modes for
>>> consistency and you can easily set the completion sources to use the
>>> semantic completion candidates in addition to the more common sources
>>> like dabbrev.
>>
>> Yes, you did. But it seems it doesn't work as it promises. It seems it
>> autompletes symbols only in a per session way (every time I start
>> editing a new file it resets all the simbols previously gathered),
>> and,
>
> What gathered symbols does semantic maintain?

The ones I had written in the current session.

>> What it's worst, its scope is limited on the open buffer, it doesn't
>> look for in included headers.
>>
>> But maybe it's only my emacs that is misconfigured.
>
> I suspect it is.
>
> As I said, it can use the semantic back end completion sets.

Have you an .emacs file to show me.
Thanks
-- 
     La morte e' un'esperienza migliore se condivisa, come il te'.
     		-- Worf, "Up The Long Ladder" (TNG), data astrale 42823.2




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

* Re: add-hook
  2011-06-05 22:28           ` add-hook daniele.g
@ 2011-06-05 23:33             ` Richard Riley
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Riley @ 2011-06-05 23:33 UTC (permalink / raw)
  To: help-gnu-emacs

dgiglio@iol.it (daniele.g) writes:

> Richard Riley <rileyrg@googlemail.com> writes:
>
>> Dgiglio@iol.it (daniele.g) writes:
>>
>>> Richard Riley <rileyrg@googlemail.com> writes:
>>>
>>>> I think I mentioned it before, but auto-complete has an excellent
>>>> completion mechanism which you can share/use across all modes for
>>>> consistency and you can easily set the completion sources to use the
>>>> semantic completion candidates in addition to the more common sources
>>>> like dabbrev.
>>>
>>> Yes, you did. But it seems it doesn't work as it promises. It seems it
>>> autompletes symbols only in a per session way (every time I start
>>> editing a new file it resets all the simbols previously gathered),
>>> and,
>>
>> What gathered symbols does semantic maintain?
>
> The ones I had written in the current session.
>
>>> What it's worst, its scope is limited on the open buffer, it doesn't
>>> look for in included headers.
>>>
>>> But maybe it's only my emacs that is misconfigured.
>>
>> I suspect it is.
>>
>> As I said, it can use the semantic back end completion sets.
>
> Have you an .emacs file to show me.
> Thanks

sure.

I stopped using semantic as I found it tripping over too often (in
parsing files, not in completion candidates). But I'm using javascript
and php and last I heard it doesnt really work with either.And I dont
know what a "bovine thingy" is ;) ...

So here's related completion stuff - it probably could be cleaned up.

from my .emacs equivalent:

  (add-to-list 'load-path "~/.emacs.d/auto-complete")
  (require 'auto-complete)
  (require 'auto-complete-config)
  (ac-config-default)
  (add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/dict")
  (setq-default
   ac-sources '(
                ac-source-abbrev
                ac-source-gtags
                ac-source-dictionary
                ac-source-words-in-all-buffer
                ac-source-words-in-buffer
                )
   )

  (global-auto-complete-mode t)


and in my custom.el

 '(ac-auto-show-menu 0.1)
 '(ac-auto-start 5)
 '(ac-candidate-limit 10)
 '(ac-dictionary-files (quote ("~/.dict" "/etc/dictionaries-common/words")))
 '(ac-menu-height 20)
 '(ac-modes (quote (emacs-lisp-mode lisp-interaction-mode c-mode cc-mode c++-mode java-mode malabar-mode clojure-mode scala-mode scheme-mode ocaml-mode tuareg-mode haskell-mode perl-mode cperl-mode python-mode ruby-mode ecmascript-mode javascript-mode js-mode js2-mode php-mode css-mode makefile-mode sh-mode fortran-mode f90-mode ada-mode xml-mode sgml-mode jde-mode org-mode jde-mode latex-mode ledger-mode mail-mode message-mode text-mode)))
 '(ac-use-fuzzy nil)
 '(ac-user-dictionary-files (quote ("~/.dict" "/etc/dictionaries-common/words")))

I have only good things to say about auto-complete and its support.

regards

r.




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

* add-hook
@ 2013-01-25 19:03 Perry Smith
  2013-01-25 19:18 ` add-hook Drew Adams
  0 siblings, 1 reply; 20+ messages in thread
From: Perry Smith @ 2013-01-25 19:03 UTC (permalink / raw)
  To: Emacs help

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

In one of my setup files I have this:

> (eval-after-load 'ruby-mode
>   '(add-hook 'ruby-mode-hook (function
> 			      (lambda ()
> 				(ruby-electric-mode t)))))

Other places, I just do the add-hook.

The reason I'm asking is because I need to do:

> (eval-after-load 'grep
>   '(add-to-list 'grep-files-aliases (cons "rails" "*.rb *.erb *.js *.css *.scss")))


because if I don't, I get an error that says grep-files-aliases is not defined.  It appears as if add-hook has smarts that add-to-list does not have but I wanted to be sure which method was preferred.

Thank you,
Perry


[-- Attachment #2: Type: text/html, Size: 1486 bytes --]

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

* RE: add-hook
  2013-01-25 19:03 add-hook Perry Smith
@ 2013-01-25 19:18 ` Drew Adams
  2013-01-26  4:03   ` add-hook Dmitry Gutov
       [not found]   ` <mailman.18346.1359173059.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 20+ messages in thread
From: Drew Adams @ 2013-01-25 19:18 UTC (permalink / raw)
  To: 'Perry Smith', 'Emacs help'

> In one of my setup files I have this: 
>
> (eval-after-load 'ruby-mode
>   '(add-hook
>      'ruby-mode-hook
>      (function
>       (lambda ()
>        (ruby-electric-mode t)))))
>
> Other places, I just do the add-hook.

You don't need the `eval-after-load' (or the `function').

> The reason I'm asking is because I need to do:
> (eval-after-load 'grep '(add-to-list 'grep-files-aliases ...))
> because if I don't, I get an error that says grep-files-aliases
> is not defined.
>
> It appears as if add-hook has smarts that add-to-list does not

Good question.  Let's ask Emacs...

Yes - see the last paragraph of `C-h f add-hook':

,----
| add-hook is a compiled Lisp function in `subr.el'.
| (add-hook HOOK FUNCTION &optional APPEND LOCAL)
| 
| Add to the value of HOOK the function FUNCTION.
| FUNCTION is not added if already present.
| FUNCTION is added (if necessary) at the beginning of the hook list
| unless the optional argument APPEND is non-nil, in which case
| FUNCTION is added at the end.
| 
| The optional fourth argument, LOCAL, if non-nil, says to modify
| the hook's buffer-local value rather than its global value.
| This makes the hook buffer-local, and it makes t a member of the
| buffer-local value.  That acts as a flag to run the hook
| functions of the global value as well as in the local value.
| 
| HOOK should be a symbol, and FUNCTION may be any valid function.  If
| HOOK is void, it is first set to nil.  If HOOK's value is a single
| function, it is changed to a list of functions.
`----

If HOOK is void then it is initialized to nil.

(add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t)))




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

* Re: add-hook
  2013-01-25 19:18 ` add-hook Drew Adams
@ 2013-01-26  4:03   ` Dmitry Gutov
       [not found]   ` <mailman.18346.1359173059.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 20+ messages in thread
From: Dmitry Gutov @ 2013-01-26  4:03 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Emacs help'

"Drew Adams" <drew.adams@oracle.com> writes:
> If HOOK is void then it is initialized to nil.
>
> (add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t)))

Or, even shorter:

(add-hook 'ruby-mode-hook 'ruby-electric-mode)



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

* Re: add-hook
       [not found]   ` <mailman.18346.1359173059.855.help-gnu-emacs@gnu.org>
@ 2013-01-26  5:33     ` Barry Margolin
  2013-01-26  6:21       ` add-hook Dmitry Gutov
  0 siblings, 1 reply; 20+ messages in thread
From: Barry Margolin @ 2013-01-26  5:33 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.18346.1359173059.855.help-gnu-emacs@gnu.org>,
 Dmitry Gutov <dgutov@yandex.ru> wrote:

> "Drew Adams" <drew.adams@oracle.com> writes:
> > If HOOK is void then it is initialized to nil.
> >
> > (add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t)))
> 
> Or, even shorter:
> 
> (add-hook 'ruby-mode-hook 'ruby-electric-mode)

Not the same. With no argument it toggles, with an argument it turns the 
mode on or off as specified by the argument.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* Re: add-hook
  2013-01-26  5:33     ` add-hook Barry Margolin
@ 2013-01-26  6:21       ` Dmitry Gutov
  0 siblings, 0 replies; 20+ messages in thread
From: Dmitry Gutov @ 2013-01-26  6:21 UTC (permalink / raw)
  To: Barry Margolin; +Cc: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <mailman.18346.1359173059.855.help-gnu-emacs@gnu.org>,
>  Dmitry Gutov <dgutov@yandex.ru> wrote:
>
>> "Drew Adams" <drew.adams@oracle.com> writes:
>> > If HOOK is void then it is initialized to nil.
>> >
>> > (add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t)))
>> 
>> Or, even shorter:
>> 
>> (add-hook 'ruby-mode-hook 'ruby-electric-mode)
>
> Not the same. With no argument it toggles, with an argument it turns the 
> mode on or off as specified by the argument.

Not really. It toggles only when the mode function is called
interactively. Otherwise, a no-argument call always means "turn on".

Try to eval this a few times, for example: (linum-mode)

In the context of ruby-electric this is irrelevant anyway, though, since
it doesn't have a concept of turning off. Whenever called, it just
modifies ruby-mode-map to use its electric commands.



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

end of thread, other threads:[~2013-01-26  6:21 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 11:26 add-hook Sebastian Tennant
2007-06-07  0:20 ` add-hook Sebastian Tennant
     [not found] ` <mailman.1696.1181175524.32220.help-gnu-emacs@gnu.org>
2007-06-07  7:16   ` add-hook Thien-Thi Nguyen
2007-06-07 10:00     ` add-hook Sebastian Tennant
     [not found]     ` <mailman.1711.1181210337.32220.help-gnu-emacs@gnu.org>
2007-06-07 14:01       ` add-hook Thien-Thi Nguyen
     [not found] <mailman.1634.1181129906.32220.help-gnu-emacs@gnu.org>
2007-06-06 12:04 ` add-hook Katsumi Yamaoka
2007-06-06 20:41 ` add-hook Robert D. Crawford
  -- strict thread matches above, loose matches on Subject: below --
2011-06-04 13:00 add-hook daniele.g
2011-06-04 14:11 ` add-hook Teemu Likonen
2011-06-04 18:35   ` add-hook daniele.g
2011-06-05 10:58     ` add-hook Richard Riley
2011-06-05 18:58       ` add-hook daniele.g
2011-06-05 20:26         ` add-hook Richard Riley
2011-06-05 22:28           ` add-hook daniele.g
2011-06-05 23:33             ` add-hook Richard Riley
2013-01-25 19:03 add-hook Perry Smith
2013-01-25 19:18 ` add-hook Drew Adams
2013-01-26  4:03   ` add-hook Dmitry Gutov
     [not found]   ` <mailman.18346.1359173059.855.help-gnu-emacs@gnu.org>
2013-01-26  5:33     ` add-hook Barry Margolin
2013-01-26  6:21       ` add-hook Dmitry Gutov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).