Emacs: .emacs file loads but does not actually work - emacs

I am on OSX and trying to map my command key to META. I have the following code in my .emacs file:
(setq mac-command-modifier 'meta)
(setq mac-escape-modifier nil)
Upon opening, emacs does not say that the file has not been loaded, so I'm assuming it has been loaded. What am I doing incorrectly here?

Related

How to program .emacs file to end up in a specific buffer?

I have this code in my .emacs file:
(load "ielm" nil t)
(switch-to-buffer "*ielm*")
(inferior-emacs-lisp-mode)
(set-buffer-modified-p nil)
In emacs 21 and earlier, I ended up with *ielm* as the current buffer, but starting with emacs 22 I end up with *GNU Emacs* as the current buffer. What changed in emacs 22 to cause the new behavior, and what can I do to automatically end up in the *ielm* buffer?
The Emacs manual, node Entering Emacs tells you:
You can also force Emacs to display a file or directory at startup by
setting the variable initial-buffer-choice to a string naming that
file or directory. The value of initial-buffer-choice may also be a
function (of no arguments) that should return a buffer which is then
displayed. If initial-buffer-choice is non-nil, then if you specify
any files on the command line, Emacs still visits them, but does not
display them initially.
You can find this node in the manual by using C-h r (open the manual) followed by i startup TAB (search the index for "startup"), and choose startup screen. (Other index choices will also take you there.)
Thanks, #Drew.
Adding the following to my .emacs file gives me the behavior I desire.
(if (= (length command-line-args) 1)
(setq initial-buffer-choice
(lambda () (get-buffer "*ielm*"))))

Elisp: possible to automatically open Emacs init file if error at start-up?

Here's the idea: if I restart Emacs after making a change to my Emacs init file, it would be very convenient if, in the event of an error at start-up, Emacs automatically opened my init file for editing
For example, if there's an error at start-up, Emacs could show the error/debug message in one window and my init file in the other window.
I'm new to Emacs Lisp and am not familiar with error-handling procedures. Are there any error-handling mechanisms/settings that could be useful? (Am honestly not sure where to even start with this one, hence the lack of any experimental code in this post...)
If you really want to do that, you can try this:
Wrap the contents of your init file in this, where CONTENTS is your originaly init file, and FILE is the absolute name (i.e., location) of your init file:
(condition-case err
(progn
(setq debug-on-error t)
CONTENTS
)
(error (find-file FILE)
(error "*INIT ERROR*: %s" (error-message-string err))))
Or perhaps a little better: Put what is in your init file now in another file - called ORIG-INIT here (again, an absolute file name), and use this as the (only) content of your init file:
(condition-case err
(progn (setq debug-on-error t)
(load-file ORIG-INIT))
(error (find-file ORIG-INIT)
(error "*INIT ERROR*: %s" (error-message-string err))))
Actually, I normally have one emacs open with the .emacs file. Then I open and close a new emacs every time I've made changes. Not as cool, I know, but then even your cursor will be where you were working.
Another thing I do is just edit a piece of code in a scrap buffer (scratch or a newly made temporary file) and execute it using C-x C-e (while standing at the end of the expression).

Octave mode in Emacs won't automatically load for a .m file [duplicate]

My Emacs opens .m files in ObjC mode. However I want to open them in Octave mode. I have already added to the .emacs file:
(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))
What else should I do? I do have Octave mode installed.
Fortunately everything is working now and unfortunately I don't remember how I fixed it :) Maybe there was an error in my .emacs earlier. This is the more correct code:
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
Autoloading is unneeded in recent versions; if you do need to enable it, note that "octave-mode" is not a typo.
(autoload 'octave-mode "octave-mod" nil t)
Use this.
;; octave-mode
(autoload 'octave-mode "octave-mode" "Loding octave-mode" t)
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
Just ran into this exact problem.
Your statement is correct, but your .emacs file probably isn't loading up correctly. Emacs searches the "HOME" variable to load up preferences, lisp code etc.
To see what your HOME variable is:
Open scratch buffer (this is a "play place" to try things out):
C-x C-b *scratch* <RET>
Evaluate this expression by typing it, then putting the cursor to the right, then hitting C-x C-e
insert (getenv "HOME")
Emacs will display your home path at the bottom (mine defaulted to ...Documents and Settings\UserName)
I haven't worked out a good way to change it, but you're supposed to be able to simply add HOME as an environment variable (that didn't work for me).
It's also talked about a bit more over here:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
Also remember that the file has to be ".emacs" and not myConfig.emacs or something of the like. Use bash command ren to rename the file (windows explorer won't let you have nameless files)

Emacs change file extension - mode association

My Emacs opens .m files in ObjC mode. However I want to open them in Octave mode. I have already added to the .emacs file:
(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))
What else should I do? I do have Octave mode installed.
Fortunately everything is working now and unfortunately I don't remember how I fixed it :) Maybe there was an error in my .emacs earlier. This is the more correct code:
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
Autoloading is unneeded in recent versions; if you do need to enable it, note that "octave-mode" is not a typo.
(autoload 'octave-mode "octave-mod" nil t)
Use this.
;; octave-mode
(autoload 'octave-mode "octave-mode" "Loding octave-mode" t)
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
Just ran into this exact problem.
Your statement is correct, but your .emacs file probably isn't loading up correctly. Emacs searches the "HOME" variable to load up preferences, lisp code etc.
To see what your HOME variable is:
Open scratch buffer (this is a "play place" to try things out):
C-x C-b *scratch* <RET>
Evaluate this expression by typing it, then putting the cursor to the right, then hitting C-x C-e
insert (getenv "HOME")
Emacs will display your home path at the bottom (mine defaulted to ...Documents and Settings\UserName)
I haven't worked out a good way to change it, but you're supposed to be able to simply add HOME as an environment variable (that didn't work for me).
It's also talked about a bit more over here:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
Also remember that the file has to be ".emacs" and not myConfig.emacs or something of the like. Use bash command ren to rename the file (windows explorer won't let you have nameless files)

How to view the files loaded in emacs at startup

How to view the files that are loaded by the emacs at start up.
I have put the following line in my .emacs file
(setq load-path (cons "~/org/org-mode/lisp/" load-path))
(require 'org-install)
and expect the file org-install.el to be displayed in the *Messages* buffer,
I have looked at the *Messages* buffer and not able to find any info on the org-install.* file name.
I use "load" rather than "require" in my .emacs because it appends a message to *Messages* regardless of whether is fails or succeeds.
If you are still confused, say ESC ESC : (load "~/org/org-mode/lisp/org-install.el") RET, and tell us what new messages have appeared in *Messages*.