emacs does not open a file from argument and syntax highlight does not work

28

3

In my latest ubuntu box,

  1. When I type for example emacs ~/.bashrc, Emacs will start but not open .bashrc. This is true for any file I pass in. I've used Emacs for several years, and have never experienced this problem before.

  2. I added (global-font-lock-mode 1);; to my .emacs file, and Emacs does recognize it, for example. "(C++/; Abbrev)", but it won't do syntax highlighting.

If you can solve any of these problems, it will be very appreciated. The following is my machine's configuration:

uname -a
Linux 2.6.35-28-generic-pae #49-Ubuntu SMP Tue Mar 1 14:58:06 UTC 2011 i686 GNU/Linux

~/.emacs
(global-font-lock-mode 1);;

Jus

Posted 2011-03-26T21:18:46.817

Reputation:

1

Better asked on http://askubuntu.com/

– Oded – 2011-03-26T21:22:11.723

1What happens if you start emacs then use C-x C-f to open ~/.bashrc? Might give you a useful error message. – None – 2011-03-26T21:27:41.200

1Does the *Messages* buffer contain anything useful? – MatthewD – 2011-03-27T02:35:39.020

1hi thanks a lot, it seems it is caused by the directory ~/.emacs.d, emacs actually complains upon startup :"~/.emacs.d already exists". So I removed ~/.emacs.d, and now everything works! (I can open files through command line argument and syntax highlighting also works now). @Tom, previously I can start emacs, and then use C-x C-f to open .bashrc, but cannot open by > emacs ~/.bashrc – None – 2011-03-27T05:13:35.007

Answers

35

I got the same problem. It was due to the fact I first used emacs with sudo. As a consequence the .emacs.d was created with super user right and I could not access it as a regular user.

By removing the .emacs.d created as root let emacs generate a new one with your user account.

Michael Dussere

Posted 2011-03-26T21:18:46.817

Reputation: 351

There really ought to be some kind of diagnostic about this. This must happen a lot when emacs is used as a system administration tool. – Jules – 2017-12-24T11:45:19.000

3or you can simply change owner sudo chown -hR <groupname>:<username> .emacs.d/ – logcat – 2013-08-05T06:11:27.013

1Yep, this fixed the problem. It'd be great if emacs showed some information about this error... – José Tomás Tocino – 2014-05-01T15:03:51.370

4

You can have both ~/.emacs file and ~/.emacs.d/ directory, but Emacs will ignore ~/.emacs.d/init.el file. Emacs only evaluates ~/.emacs.d/init.el when there is no ~/.emacs. (Thanks, pyrocrasty).

See: The Emacs Initialization File @ GNU Emacs Manual.

Mirzhan Irkegulov

Posted 2011-03-26T21:18:46.817

Reputation: 1 134

That's not true at all. I used a ~/.emacs file for years and I certainly always had a ~/.emacs.d/ directory. There won't be any conflict unless you have a ~/.emacs file and a ~/.emacs.d/init.el file at the same time, and even then, Emacs will just ignore one (I believe it prioritizes ~/.emacs). – pyrocrasty – 2015-05-16T17:27:57.967

If you correct an error, in the future please don't strike it out, but just remove it entirely. Thanks. I left the comment stay so you can actually tell its posted that you corrected your answer. (They may upvote you or undo a downvote.) – slhck – 2015-05-16T17:44:34.307

-1

initial-buffer-choice in startup.el allows initial file customization.

Buglouse

Posted 2011-03-26T21:18:46.817

Reputation: 101

2perhaps some context would be helpful. An example config? – JoshP – 2012-09-28T14:34:19.790