unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* turning line mode on/off with defun not working
@ 2013-12-05 17:28 Wes James
  2013-12-05 17:31 ` Drew Adams
  0 siblings, 1 reply; 15+ messages in thread
From: Wes James @ 2013-12-05 17:28 UTC (permalink / raw)
  To: help-gnu-emacs

I have these lines in my .emacs, but they don't work.  Why?

(defun lnon()
  "Turn line numbers on"
  (global-linum-mode t)
)

(defun lnoff()
  "Turn line numbers off"
  (global-linum-mode 0)
)

I press alt-x and then type in lnon or lnoff but it says [No Match]

I have this and it works:

; define function to shutdown emacs server instance                                                           
(defun ked ()
  "Save buffers, Quit, and Shutdown (kill) server"
  (interactive)
   (save-some-buffers)
  (kill-emacs)
)

What is the difference?

Thanks,

-wes

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

* RE: turning line mode on/off with defun not working
  2013-12-05 17:28 turning line mode on/off with defun not working Wes James
@ 2013-12-05 17:31 ` Drew Adams
  2013-12-05 17:54   ` Wes James
  0 siblings, 1 reply; 15+ messages in thread
From: Drew Adams @ 2013-12-05 17:31 UTC (permalink / raw)
  To: Wes James, help-gnu-emacs

> What is the difference?

(interactive)

See the Elisp manual - use `i interactive'.

Or use `C-h f interactive'.



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

* Re: turning line mode on/off with defun not working
  2013-12-05 17:31 ` Drew Adams
@ 2013-12-05 17:54   ` Wes James
  0 siblings, 0 replies; 15+ messages in thread
From: Wes James @ 2013-12-05 17:54 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

On Dec 05, 2013, at 10:31 AM, Drew Adams <drew.adams@oracle.com> wrote:

What is the difference?

(interactive)

See the Elisp manual - use `i interactive'.

Or use `C-h f interactive'.
 
That did it.  Thanks.

(defun lnon ()
  "Turn line numbers on"
  (interactive)
  (global-linum-mode t)
)

(defun lnoff ()
  "Turn line numbers off"
  (interactive)
  (global-linum-mode 0)
)

-wes

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

* turning line mode on/off with defun not working
@ 2013-12-05 18:42 Wes James
  2013-12-05 18:48 ` Drew Adams
  0 siblings, 1 reply; 15+ messages in thread
From: Wes James @ 2013-12-05 18:42 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs



On Dec 05, 2013, at 10:31 AM, Drew Adams <drew.adams@oracle.com> wrote:

What is the difference?

(interactive)

See the Elisp manual - use `i interactive'.

Or use `C-h f interactive'.
 
----------
I can see how to use C-h f interactive.

How do you use 'i interactive'. I've tried c-x and m-x and not sure how this one works.

(sorry if the indent/quoting is crappy, icloud mail is definitely lacking....)

Thanks,

-wes

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

* RE: turning line mode on/off with defun not working
  2013-12-05 18:42 Wes James
@ 2013-12-05 18:48 ` Drew Adams
  2013-12-05 19:00   ` Wes James
  0 siblings, 1 reply; 15+ messages in thread
From: Drew Adams @ 2013-12-05 18:48 UTC (permalink / raw)
  To: Wes James; +Cc: help-gnu-emacs

>> See the Elisp manual - use `i interactive'.
>> Or use `C-h f interactive'.
>
> I can see how to use C-h f interactive.
> How do you use 'i interactive'. I've tried c-x and m-x and
> not sure how this one works.

First, bravo for trying, and then asking for help.

`i' is bound to command `Info-index' when in Info mode.

So to use it you need to first be visiting a manual (in this
case, the Elisp manual) in Info mode.

To do that: `C-h i' invokes command `info'.  Then choose the
Elisp manual.  Then use `i' to find something that is in the
index, in this case `interactive'.



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

* Re: turning line mode on/off with defun not working
  2013-12-05 18:48 ` Drew Adams
@ 2013-12-05 19:00   ` Wes James
  0 siblings, 0 replies; 15+ messages in thread
From: Wes James @ 2013-12-05 19:00 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs



On Dec 05, 2013, at 11:48 AM, Drew Adams <drew.adams@oracle.com> wrote:

See the Elisp manual - use `i interactive'.
Or use `C-h f interactive'.
I can see how to use C-h f interactive.
How do you use 'i interactive'. I've tried c-x and m-x and
not sure how this one works.

First, bravo for trying, and then asking for help.

`i' is bound to command `Info-index' when in Info mode.

So to use it you need to first be visiting a manual (in this
case, the Elisp manual) in Info mode.

To do that: `C-h i' invokes command `info'. Then choose the
Elisp manual. Then use `i' to find something that is in the
index, in this case `interactive'.
 

Thanks for info, that worked :)

-wes

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

* Re: turning line mode on/off with defun not working
       [not found] <mailman.8198.1386264536.10748.help-gnu-emacs@gnu.org>
@ 2013-12-06 18:35 ` Emanuel Berg
  2013-12-06 19:21   ` Wes James
       [not found]   ` <mailman.8418.1386360511.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-06 18:35 UTC (permalink / raw)
  To: help-gnu-emacs

Wes James <comptekki@me.com> writes:

> I have these lines in my .emacs, but they don't
> work. Why?

(interactive), for starters. But you probably won't to
enable this buffer-local. Also, check out the below
Elisp for two simple "toggle" defuns - you don't need
one to turn it off, and one to turn it on - think of it
as a binary state machine (i.e., with two states). It
only requires one operation, "do whatever I don't do
know".

;;; show point position
;; column
(defun char-mode ()
  "Mode bar: Show the index of the character at point (first = 0)."
  (interactive)
  (set-variable 'column-number-mode
                (not column-number-mode)
                t) ) ; local
(defalias 'cols 'char-mode)
;; line
(defun line-mode ()
  "Mode bar: Show the line number at point (first = 1)."
  (interactive)
  (set-variable 'line-number-mode
                (not line-number-mode)
                t) ) ; local
(defalias 'lines 'line-mode)

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: turning line mode on/off with defun not working
  2013-12-06 18:35 ` Emanuel Berg
@ 2013-12-06 19:21   ` Wes James
       [not found]   ` <mailman.8418.1386360511.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 15+ messages in thread
From: Wes James @ 2013-12-06 19:21 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

On Fri, Dec 6, 2013 at 11:35 AM, Emanuel Berg <embe8573@student.uu.se>wrote:

> Wes James <comptekki@me.com> writes:
>
> > I have these lines in my .emacs, but they don't
> > work. Why?
>
> (interactive), for starters. But you probably won't to
> enable this buffer-local. Also, check out the below
> Elisp for two simple "toggle" defuns - you don't need
> one to turn it off, and one to turn it on - think of it
> as a binary state machine (i.e., with two states). It
> only requires one operation, "do whatever I don't do
> know".
>
> ;;; show point position
> ;; column
> (defun char-mode ()
>   "Mode bar: Show the index of the character at point (first = 0)."
>   (interactive)
>   (set-variable 'column-number-mode
>                 (not column-number-mode)
>                 t) ) ; local
> (defalias 'cols 'char-mode)
> ;; line
> (defun line-mode ()
>   "Mode bar: Show the line number at point (first = 1)."
>   (interactive)
>   (set-variable 'line-number-mode
>                 (not line-number-mode)
>                 t) ) ; local
> (defalias 'lines 'line-mode)
>
> --
> Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
> underground experts united:  http://user.it.uu.se/~embe8573
>


Thank you.  I appreciate this.

-wes


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

* Re: turning line mode on/off with defun not working
       [not found]   ` <mailman.8418.1386360511.10748.help-gnu-emacs@gnu.org>
@ 2013-12-06 21:35     ` Emanuel Berg
  2013-12-06 21:42       ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2013-12-06 21:35 UTC (permalink / raw)
  To: help-gnu-emacs

Wes James <comptekki@gmail.com> writes:

> Thank you.  I appreciate this.

In that case, let me tell you some more. Those
interactive defuns are handy for situations unforeseen,
when you suddenly need them. But for certain modes, you
know you always want it (or you know you never want
it). In those cases you can set (or unset)
automatically upon invocation, with hooks. Those hooks
do the job for you in 99% of the cases, and in the 1%
case, you still have those interactive defuns to set it
manually.

So to enable line-number-mode for C and C++
programming, it may look like this:

(setq c-mode-hook 'lines)
(setq c++-mode-hook (lambda () (lines) (abbrev-mode 0)))

In C++, I also disable abbrev-mode (for some reason),
but it is only a good thing because as you see,
enabling line-number-mode looks somewhat
different. Note that the above are for my lines stuff -
to use the actual functions directly, probably you need
(lambda () (line-number-mode 1)) for the modes where
you want it.

Also, those hooks can be examined like any
variables. You can examine your hooks with C-h v, and
if they are not nil, instead of setq (so not to
overwrite what's there), use add-hook (and then *quote*
the mode, like this 'c-mode-hook).

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: turning line mode on/off with defun not working
  2013-12-06 21:35     ` Emanuel Berg
@ 2013-12-06 21:42       ` Emanuel Berg
  2013-12-06 22:35         ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2013-12-06 21:42 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> In that case, let me tell you some more. Those
> interactive defuns are handy for situations unforeseen,
> when you suddenly need them. But for certain modes, you
> know you always want it (or you know you never want
> it). In those cases you can set (or unset)
> automatically upon invocation, with hooks. Those hooks
> do the job for you in 99% of the cases, and in the 1%
> case, you still have those interactive defuns to set it
> manually.
>
> So to enable line-number-mode for C and C++
> programming, it may look like this:
>
> (setq c-mode-hook 'lines)
> (setq c++-mode-hook (lambda () (lines) (abbrev-mode 0)))
>
> In C++, I also disable abbrev-mode (for some reason),
> but it is only a good thing because as you see,
> enabling line-number-mode looks somewhat
> different. Note that the above are for my lines stuff -
> to use the actual functions directly, probably you need
> (lambda () (line-number-mode 1)) for the modes where
> you want it.

No, that seems not to be local (?). Well, the way I did
it with `lines' above, that works, so use that if you
want it the way I describe it.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: turning line mode on/off with defun not working
  2013-12-06 21:42       ` Emanuel Berg
@ 2013-12-06 22:35         ` Emanuel Berg
  2013-12-06 23:05           ` Wes James
  0 siblings, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2013-12-06 22:35 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> No, that seems not to be local (?). Well, the way I did
> it with `lines' above, that works, so use that if you
> want it the way I describe it.

This was a bit confusing:

(line-number-mode 1)
(line-number-mode 0)
(set-variable 'line-number-mode t t)
(set-variable 'line-number-mode nil t)

It would seem like the first two lines work on the
global scope, only, once you have run either of lines
three and four, the first two lines seem to work on the
local instance instead. Well, lines three and four work
on the *variable*, which they locally set to the given
value. In lines one and two, I just pass an argument 1
or 0 to the *function*. I guess the correct place to
examine this would be that function (so there is a
mode, a function, *and* a variable with the same name)
and see if it somehow changes behaviour based on the
existence of a local instance, *or* if this is deeper
in the Emacs architecture: it wouldn't be a chock if
local instances take precedence. Well, perhaps someone
could tell us (me) straight off?

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

* Re: turning line mode on/off with defun not working
  2013-12-06 22:35         ` Emanuel Berg
@ 2013-12-06 23:05           ` Wes James
  2013-12-06 23:16             ` Emanuel Berg
  0 siblings, 1 reply; 15+ messages in thread
From: Wes James @ 2013-12-06 23:05 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

On Fri, Dec 6, 2013 at 3:35 PM, Emanuel Berg <embe8573@student.uu.se> wrote:

> Emanuel Berg <embe8573@student.uu.se> writes:
>
> > No, that seems not to be local (?). Well, the way I did
> > it with `lines' above, that works, so use that if you
> > want it the way I describe it.
>
> This was a bit confusing:
>
> (line-number-mode 1)
> (line-number-mode 0)
> (set-variable 'line-number-mode t t)
> (set-variable 'line-number-mode nil t)
>
> It would seem like the first two lines work on the
> global scope, only, once you have run either of lines
> three and four, the first two lines seem to work on the
> local instance instead. Well, lines three and four work
> on the *variable*, which they locally set to the given
> value. In lines one and two, I just pass an argument 1
> or 0 to the *function*. I guess the correct place to
> examine this would be that function (so there is a
> mode, a function, *and* a variable with the same name)
> and see if it somehow changes behaviour based on the
> existence of a local instance, *or* if this is deeper
> in the Emacs architecture: it wouldn't be a chock if
> local instances take precedence. Well, perhaps someone
> could tell us (me) straight off?
>
>
 Thanks for the mini tutorial.

I was able to change the line on/off with:

(defun lt()
  "Toggle line numbers on/off"
  (interactive)
  (global-linum-mode)
)

I just do M-x and type "lt" to do line number toggling on and off.

Bye the way, I've seen some code with (defun name "space" ().....)

Should there be a space after the defun name or not for style
recommendation? It seems to work either way:

(defun name ()...)  or (defun name()...)

Thanks again,

-wes


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

* Re: turning line mode on/off with defun not working
  2013-12-06 23:05           ` Wes James
@ 2013-12-06 23:16             ` Emanuel Berg
  2013-12-07  9:06               ` PJ Weisberg
       [not found]               ` <mailman.8440.1386407185.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-06 23:16 UTC (permalink / raw)
  To: help-gnu-emacs

Wes James <comptekki@gmail.com> writes:

> (global-linum-mode)

So there is a third way to do it. But like I said, I
don't like the idea of having it global. If you want it
global, I guess you could put that line in your .emacs
(just the line) and be done with it.

> (defun name ()...) or (defun name()...)

Both works but I like the whitespace there. Because
that is actually an empty list (or nil), and not a
place where you put parameters (like it is in C) - or,
it is both in Lisp.

Try it yourself with nil instead of the empty
parenthesis pair. (Then, obviously you need the
whitespace.)

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573



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

* Re: turning line mode on/off with defun not working
  2013-12-06 23:16             ` Emanuel Berg
@ 2013-12-07  9:06               ` PJ Weisberg
       [not found]               ` <mailman.8440.1386407185.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 15+ messages in thread
From: PJ Weisberg @ 2013-12-07  9:06 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

On Dec 6, 2013 3:48 PM, "Emanuel Berg" <emanuel.berg.8573@student.uu.se>
wrote:
>
> Wes James <comptekki@gmail.com> writes:
>
> > (defun name ()...) or (defun name()...)
>
> Both works but I like the whitespace there. Because
> that is actually an empty list (or nil), and not a
> place where you put parameters (like it is in C) - or,
> it is both in Lisp.
>
> Try it yourself with nil instead of the empty
> parenthesis pair. (Then, obviously you need the
> whitespace.)

You *can* do that, but that doesn't mean you should.  Sure, () and nil are
always interchangeable, but only one of them *looks* like an empty list of
parameters.  It always takes my brain an extra moment to process when I see
nil somewhere where I'm expecting to see a list.


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

* Re: turning line mode on/off with defun not working
       [not found]               ` <mailman.8440.1386407185.10748.help-gnu-emacs@gnu.org>
@ 2013-12-07 13:28                 ` Emanuel Berg
  0 siblings, 0 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-12-07 13:28 UTC (permalink / raw)
  To: help-gnu-emacs

PJ Weisberg <pjweisberg@gmail.com> writes:

>> Both works but I like the whitespace there. Because
>> that is actually an empty list (or nil), and not a
>> place where you put parameters (like it is in C) -
>> or, it is both in Lisp.  Try it yourself with nil
>> instead of the empty parenthesis pair. (Then,
>> obviously you need the whitespace.)
>
> You *can* do that, but that doesn't mean you should.
> Sure, () and nil are always interchangeable, but only
> one of them *looks* like an empty list of parameters.
> It always takes my brain an extra moment to process
> when I see nil somewhere where I'm expecting to see a
> list.

I agree, I use nil as "unset" or "none" or "false" and
() as the empty list. My point was that () *is* an
empty list, it is not just two chars that denote a
place where you should put params, and that place
happens to be empty.

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


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

end of thread, other threads:[~2013-12-07 13:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-05 17:28 turning line mode on/off with defun not working Wes James
2013-12-05 17:31 ` Drew Adams
2013-12-05 17:54   ` Wes James
  -- strict thread matches above, loose matches on Subject: below --
2013-12-05 18:42 Wes James
2013-12-05 18:48 ` Drew Adams
2013-12-05 19:00   ` Wes James
     [not found] <mailman.8198.1386264536.10748.help-gnu-emacs@gnu.org>
2013-12-06 18:35 ` Emanuel Berg
2013-12-06 19:21   ` Wes James
     [not found]   ` <mailman.8418.1386360511.10748.help-gnu-emacs@gnu.org>
2013-12-06 21:35     ` Emanuel Berg
2013-12-06 21:42       ` Emanuel Berg
2013-12-06 22:35         ` Emanuel Berg
2013-12-06 23:05           ` Wes James
2013-12-06 23:16             ` Emanuel Berg
2013-12-07  9:06               ` PJ Weisberg
     [not found]               ` <mailman.8440.1386407185.10748.help-gnu-emacs@gnu.org>
2013-12-07 13:28                 ` Emanuel Berg

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