Add a TeX symbol in the Emacs init file - emacs

I am trying to add the following code to my .emacs init file:
(TeX-add-symbols '("eqref" TeX-arg-ref))
But I cannot get it to work. I get the following error when running emacs t.tex (t.tex is here a sample text file) from the command line:
Warning (initialization): An error occurred while loading `.emacs':
Symbol's function definition is void: TeX-add-symbols
I am using GNU Emacs version 23.3.1 on Ubuntu 12.04. My .emacs init file looks like
(setq TeX-auto-parse t)
(setq TeX-electric-escape t)
(setq reftex-label-alist '((nil ?e nil "~\\eqref{%s}" nil nil)))
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(TeX-add-symbols '("eqref" TeX-arg-ref))
If I enter ESC-: (i.e. running the command eval-expression) and enter
(TeX-add-symbols '("eqref" TeX-arg-ref)) at the prompt it works fine. (That is after running this, I can enter \eqref in the buffer and it works as expected.. But this is not a good solution, having to enter this code manually each time I edit a file.. That is the reason why I try to set it up in the .emacs file..)
Background information for this question:
I have a problem with using the AucTeX style amsmath.el.. it seems that it is not loaded properly on my machine.. For more information, see Using \eqref with RefTeX.

You have to evaluate the code after LaTeX-mode is activated, otherwise you get the error Symbol's function definition is void: TeX-add-symbols. You can add that function to the hook of LaTeX-mode. In order to override possible other eqref macro definitions, you should add a dummy (ignore) to the definition of the macro. This code, in your .emacs, does the trick:
(add-hook 'LaTeX-mode-hook
'(lambda ()
(TeX-add-symbols '("eqref" TeX-arg-ref (ignore)))))

Related

write mail with mutt using emacs

I am using both mutt and emacs to write mail.
I use, until recent time, this code into my .emacs :
; corrector
(add-hook 'mail-mode-hook 'flyspell-mode)
; Do not cut words
(global-visual-line-mode t)
; open mail-mode when emacs is invoked by mutt
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
; wrap email body
(add-hook 'mail-mode-hook 'turn-on-auto-fill)
(add-hook 'mail-mode-hook 'turn-on-filladapt-mode)
But it is not working anymore. When I write a email with emacs I have no flyspell enable and the mail-mode does not wrap the text.
When I try to launch the mail-mode manually, I have a error :
File mode specification error: (void-function turn-on-filladapt-mode)
Making completion list... [2 times]
run-hooks: Symbol's function definition is void: turn-on-filladapt-mode
The problem was caused by the missing package emacs-goodies.el (in debian sid) which include filladapt.

Emacs Auctex compile error: "Use M-x make-directory RET RET to create the directory and its parents"

I am running emacs 23.3.1 on ubuntu 12.04 with auctex 11.86. Whenever I go to compile a latex document (using C-c C-c), if there are no errors, everything compiles just fine. However, if there are any errors it will tell me to use C-` to view errors, if I do so, I get this error message
Use M-x make-directory RET RET to create the directory and its parents
and it goes away after a couple seconds. Then it takes me to another screen that explains the error in the latex code. However, now I cannot simply do C-x 1 to get back to the latex code. I have to C-x C-c and restart emacs.
This is my .emacs file
(setq backup-by-copying t
backup-directory-alist '(("." . "~/.emacsBkups"))
delete-old-versions t
kept-new-versions 5
kept-old-versions 2
version-control t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-PDF-mode t)
;;(require 'ess-site)
;;(ess-toggle-underscore nil)
(require 'whitespace)
(setq whitespace-style '(lines-tail face))
(add-hook 'c-mode-hook 'whitespace-mode)
(add-hook 'c++-mode-hook 'whitespace-mode)
(add-hook 'python-mode-hook 'whitespace-mode)
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(c-set-offset (quote cpp-macro) 0 nil)
(setq TeX-view-program-list '(("Evince" "evince --page-index=%(outpage) %o")))
(setq TeX-view-program-selection '((output-pdf "Evince")))
Sometimes AUCTeX gets confused parsing the log of (La)TeX compilation and isn't able to guess the correct line raising the error. In some cases AUCTeX issues an obscure message "Error occured after last TeX file closed", when there are unbalanced parentheses, in your case it suggests you to create a new directory. To help AUCTeX finding the correct line raising the error you can add the -file-line-error option to latex or pdflatex by customizing the variable LaTeX-command-style. To do this add the following code to your .emacs:
(setq LaTeX-command-style '(("" "%(PDF)%(latex) -file-line-error %S%(PDFout)")))
See also the AUCTeX FAQ:
8. Why does TeX-next-error (C-c `) fail?
When writing the log file, TeX puts information related to a file,
including error messages, between a pair of parentheses. AUCTeX
determines the file where the error happened by parsing the log file
and counting the parentheses. This can fail when there are other,
unbalanced parentheses present.
As a workaround you can activate so-called file:line:error messages
for the log file. (Those are are easier to parse, but may lack some
details.) Either you do this in the configuration of your TeX system
(consult its manual to see where this is) or you add a command line
switch to the (la)tex call, e.g. by customizing LaTeX-command-style or
TeX-command-list.

py-python-command ignored

I'm using python-mode 6.0.1 on OS X, emacs 23.3 (http://emacsformacosx.com/ version).
I'm trying to get C-c C-c to default to python 3.
I have the following in my .emacs:
(setq py-python-command "/usr/local/bin/python3")
And when I run C-h b py-python-command, it tells me the value is that (correctly).
However, running C-c C-c still opens 2.7.2.
I also tried adding:
(setq py-which-shell "/usr/local/bin/python3")
as suggested here: Both Python 2 and 3 in Emacs, but that doesn't change anything (py-which-shell does get changed, but it still launches 2.7.2).
Any ideas?
Try adding the following code to your Emacs init file:
(add-hook 'python-mode-hook
(lambda ()
(setq py-python-command "python3")
(setq py-default-interpreter "python3")))
py-default-interpreter for now is an alias only, delivered for backward compatibility
You might have encountered a bug.
Please file a report giving some example code at
https://bugs.launchpad.net/python-mode
Should the buffer code contain a shebang specifying pythonVERSION , than this takes precedence over default setting.
You may enforce executing buffer through specific pythonVERSION by calling
a command of class py-execute-buffer-pythonVERSION
See menu PyExec, entry Execute buffer ...

Loading fic-mode in emacs

This answer gave me the solution I needed. The only problem for me, is that I have to load it, namely fic-mode, manually. More explicitly, whenever I open a c++ file, I have to do M-x fic-mode and then M-x font-lock-fontify-buffer in order to have it really up and running. In my .emacs I have
(require 'fic-mode)
(add-hook 'c++-mode-hook '(lambda () (fic-mode 1)))
but it doesn't do the trick.
Do you have any suggestions how to make it available automatically?
Try the following: create a new file containing the following three lines:
(setq load-path (cons "/path/to/fic-mode-directory" load-path))
(require 'fic-mode)
(add-hook 'c++-mode-hook 'turn-on-fic-mode)
Replace "/path/to/fic-mode-directory" with the absolute path to the directory in which you saved fic-mode.el.
Then from the command line, run
emacs -Q -l /path/to/file
where /path/to/file is the path to the above file.
Now type C-x C-f test.cpp.
Is fic-mode turned on in the resulting buffer?

elisp: call command on current file

I want to set a key in emacs to perform a shell command on the file in the buffer, and revert the buffer without prompting. The shell command is: p4 edit 'currentfilename.ext'
(global-set-key [\C-E] (funcall 'revert-buffer 1 1 1))
;; my attempt above to call revert-buffer with a non-nil
;; argument (ignoring the shell command for now) -- get an init error:
;; Error in init file: error: "Buffer does not seem to be associated with any file"
Completely new to elisp. From the emacs manual, here is the definition of revert-buffer:
Command: revert-buffer &optional ignore-auto noconfirm preserve-modes
Thanks!
The actual error you're seeing is because you've specified the global-set-key incorrectly, namely the function call. What you want is:
(global-set-key (kbd "C-S-e") '(lambda () (revert-buffer t t t)))
You had the funcall actually evaluating when your .emacs was loading, which is what caused the error.
Then, to get the whole thing, you can create a command like:
(defun call-something-on-current-buffers-file ()
"run a command on the current file and revert the buffer"
(interactive)
(shell-command
(format "/home/tjackson/bin/dummy.sh %s"
(shell-quote-argument (buffer-file-name))))
(revert-buffer t t t))
(global-set-key (kbd "C-S-e") 'call-something-on-current-buffers-file)
Obviously customize the command, and add error checking if you want.
Maybe using the minor mode "auto-revert-mode" is an option.
Just enable it on the current buffer:
M-x "auto-revert-mode"
and always ensure the buffer is saved, before executing an external command.