Problem with add hook comments

Discussion of Emacs Lisp

Problem with add hook comments

Postby Rob_K » Sun Mar 15, 2015 3:36 am

Hi all,

Wonder if you could help me. I am running Emacs on Mac OSX and I am a newbe trying to set up my environment and learn a little lisp along the way. I have been trying to get emacs to turn on line numbering when in C/C++ mode amongst other things, but every time I try to use anything more complex than a one line thing, it doesn't seem to work. Here is the code I found (I still have to scrounge code at the moment to learn).
Code: Select all
(defun my-c-mode-common-hook ()
  (line-number-mode 1))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


Firstly is the syntax here correct? it looks right judging by the amount of lisp I have looked at over the past few days to solve this problem.
And is there something obvious that I might be missing? e.g. .emacs file in wrong location or some sort of header line needed in .emacs file. I can post full .emacs file so far if it helps it's only 10 odd lines but got told off in a different forum for doing that so please let me know what is required to help me move on from this little block please.

Kind regards
Rob
Rob_K
 
Posts: 2
Joined: Sun Mar 15, 2015 3:15 am

Re: Problem with add hook comments

Postby Rob_K » Wed Mar 25, 2015 2:40 pm

Can anyone help me with this at all?
Rob_K
 
Posts: 2
Joined: Sun Mar 15, 2015 3:15 am

Re: Problem with add hook comments

Postby Goheeca » Fri Mar 27, 2015 12:26 am

Just try
Code: Select all
(line-number-mode 1)

in the .emacs file alone, it's doing nothing. I'm using
Code: Select all
(global-linum-mode t)

therefore try to replace it in your code.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
User avatar
Goheeca
 
Posts: 271
Joined: Thu May 10, 2012 12:54 pm

Re: Problem with add hook comments

Postby edgar-rft » Fri Mar 27, 2015 3:20 am

line-number-mode and linum-mode are two completely different things. line-number-mode switches the display of line and column numbers in the mode line, while linum-mode displays line numbers at the left margin. linum-mode significantly slows down Emacs when editing big files.

Try M-x line-number-mode to see if the display of line and column numbers in the Emacs mode line changes between "Cn", where n ist the column number, and "(n,m)", where n ist the column and m ist the line number.

Rob_K wrote:... every time I try to use anything more complex than a one line thing, it doesn't seem to work ...

I'm sorry but you need to describe what exactly doesn't work or what you think should have happened. From the description in the first post above I really don't have the slightest clue what your problem is at all.

I can tell you that with Emacs 24.4.1 on Debian Linux the following line in my .emacs file:

Code: Select all
(line-number-mode t)

as well as M-x line-number-mode while Emacs is running, both switch the display of line and column numbers in the mode line as described above.

Rob_K wrote:... is the syntax here correct?

I can see no syntax mistakes, but I'm using Emacs for Lisp and not for C programming, so I can't tell you if c-mode-common-hook is the right hook for switching the display of line and column numbers in Emacs c-mode.

Rob_K wrote:... is there something obvious that I might be missing? e.g. .emacs file in wrong location ...

Since you haven't written where you have stored your .emacs file I can't tell you if it's the right or wrong location. Also I'm on Linux and not on a Mac, so I don't know where Emacs is looking for the .emacs file on a Mac. I think that Emacs should automatically find the .emacs file if the file is stored in the $HOME directory of the underlying BSD Unix.

If you look in the Emacs *messages* buffer right after you started Emacs, there should be messages what files Emacs has loaded at startup.

Or add a line like this to your .emacs file:

Code: Select all
(message "Hello Emacs!")

Then look in the *messages* buffer after you started Emacs to see if your "Hello Emacs!" message was printed there.

Rob_K wrote:... or some sort of header line needed in .emacs file?

There is no special header line needed in an .emacs file.

Ask Google for a PDF copy of Bob Glickstein's book "Writing GNU Emacs Extensions", it's the best book I know about Emacs customisation.

- edgar
edgar-rft
 
Posts: 224
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany


Return to Emacs Lisp

Who is online

Users browsing this forum: No registered users and 2 guests

cron