Loading fic-mode in emacs - 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?

Related

How to remove the directory .t2d on C-c C-c Clean / M-x TeX-clean?

I use the following code in .emacs to clean the working directory from
unwanted files.
(eval-after-load 'latex
'(progn
(setq LaTeX-clean-intermediate-suffixes (delete "\\.synctex\\.gz" LaTeX-clean-intermediate-suffixes))
(setq LaTeX-clean-intermediate-suffixes (append
LaTeX-clean-intermediate-suffixes
(list "\\.bcf" "\\.synctex\\.gz(busy)" "-blx\\.bib" "\\.run\\.xml" "\\.fdb_latexmk" "\\.fls" "\\.ptc")))
(setq LaTeX-clean-output-suffixes (append LaTeX-clean-output-suffixes (list "\\.synctex\\.gz")))
))
If my LaTeX document contains an error, the current directory contains a folder
.t2d (I compile with texi2dvi -p from within Emacs/AUCTeX). I have to
manually switch to the working directory to remove this folder as, otherwise,
the document would not compile (in fact, compilation would stop with the same
error [in most of the cases]). The idea is therefore to include \\.t2d in the
above list of files being removed on C-c C-c Clean. However, if I do so, C-c
C-c Clean says TeX-clean: Removing old name: is a directory: qrm.t2d. How can
directories be removed on C-c C-c Clean?
The hint from lawlist's comment brought the solution. I first discovered that texi2dvi --mostly-clean already cleans a lot (including the unwanted directory .t2d). I then simply used a rm to remove further unwanted files -- everything wrapped so that I can call it via C-c C-c tidy:
(add-hook 'LaTeX-mode-hook
(lambda ()
;; texi2dvi
(add-to-list 'TeX-command-list
'("texi2dvi" "PDFLATEX='pdflatex --shell-escape -synctex=1 -file-line-error' texi2dvi --max-iterations=5 -p %s.tex" TeX-run-command nil t :help "Run texi2dvi") t)
;; clean
(add-to-list 'TeX-command-list
'("tidy" "texi2dvi --mostly-clean %s.tex; rm %s.pdf \"%s.synctex.gz(busy)\"" TeX-run-command nil t :help "Run clean") t)
;; default
(setq TeX-command-default "texi2dvi")))

Emacs and CWB under Windows

I'm trying to use the Edinburgh Concurrency Workbench (http://homepages.inf.ed.ac.uk/perdita/cwb/) with Emacs under Windows. I have placed the file cwb.el under C:\emacs\emacs-22.3\emacs-stuff. My .emacs file is located at C:\emacs and has the following content:
(setq load-path ; Look in my own library first.
(cons (expand-file-name "C:\emacs\emacs-22.3\emacsstuff")
load-path))
(autoload 'cwb "cwb" "Run a CWB process." t)
(autoload 'cwb-file-mode "cwb" "Major mode for editing CWB source." t)
(add-hook 'cwb-load-hook
(function
(lambda ()
(setq cwb-program-name "cwb7")))) ;; only necessary if your v7 isn't
;; called cwb
Yet, when I enter "M-x cwb", I get "Cannot open load file: cwb".
I tried to follow the instruction here: http://homepages.inf.ed.ac.uk/perdita/cwb/doc/emacs.html.
Thanks
In Emacs Lisp strings, backslash is an escape character, similar to C, so "C:\emacs\emacs-22.3\emacsstuff" ends up being "C:^[macs^[macs-22.3^[macsstuff". (You can try it with either M-: or M-x ielm.)
You can either write the path with forward slashes instead ("C:/emacs/emacs-22.3/emacsstuff") or use double backslashes ("C:\\emacs\\emacs-22.3\\emacsstuff").

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.

How do I automatically get paredit in a emacs nrepl session?

I have the following line in my emacs init file.
(setq auto-mode-alist (cons `("\*nrepl\*" . paredit-mode) auto-mode-alist))
I check that this works by creating a new buffer called *nrepl* Ctrl-x-f *nrepl*. Yes, the *nrepl* buffer has Paredit active, paredit-mode was enabled.
I close the *nrepl* buffer without saving it.
I start up a nrepl session by typing M-x nrepl-jack-in. The nrepl server starts up and I am presented with the nrepl repl. The nrepl repl is also called *nrepl*, however Paredit is not enabled.
What am I doing wrong?
You're confusing buffers and files: auto-mode-alist matches file names against regexps to decide which mode to use when editing those files. But *nrepl* is a buffer that does not contain a file, so auto-mode-alist has no effect for it.
Instead, you probably want to figure out which major-mode *nrepl* uses and then use (add-hook '<the-major-mode>-hook 'paredit-mode).
To put it simply - you need the following code:
(add-hook 'nrepl-mode-hook 'paredit-mode) ; for nrepl.el <= 0.1.8
(add-hook 'nrepl-repl-mode-hook 'paredit-mode) ; for nrepl.el > 0.1.8
Which is equivalent to the longer form:
(add-hook 'nrepl-mode-hook (lambda () (paredit-mode +1)))
(add-hook 'nrepl-mode-hook 'paredit-mode)
is what they suggest on the nrepl github page

P4CONFIG with emacs

I would like to see examples of how to setup perforce, using the config file functionality where emacs is used as the diff and merge programs (P4DIFF and P4MERGE settings). Even better if this is on Windows.
I'm also struggling with getting the P4EDITOR to work correctly when using emacsclientw, specifically specifying the alternate-editor functionality.
Any tips, suggestions, example configs are very welcome.
Here's a different trick I used to use. It adds a few command line options to emacs so that you can do diffs and merges in a new emacs instance (again using ediff).
;; -diff
(defun command-line-diff (switch)
(let ((file1 (pop command-line-args-left))
(file2 (pop command-line-args-left)))
(ediff file1 file2)))
(add-to-list 'command-switch-alist '("-diff" . command-line-diff))
;; -merge
(defun command-line-merge (switch)
(let ((base (pop command-line-args-left))
(sccs (pop command-line-args-left))
(mine (pop command-line-args-left))
(merg (pop command-line-args-left)))
(ediff-merge-with-ancestor sccs mine base () merg)))
(add-to-list 'command-switch-alist '("-merge" . command-line-merge))
Just put that in your .emacs file. Then you can set your P4DIFF program to be emacs -diff and your P4MERGE program to be emacs -merge.
I'm assuming you're already using p4.el.
Here's a function that will allow you to set your p4-client-config easily:
(defun p4-go (config)
(interactive
(list (read-file-name "P4 Config file: "
(concat (getenv "HOME") "/etc/perforce/")
""
t)))
(p4-set-client-config (expand-file-name config))
t)
Then I just run M-x p4-go <RET> conf <RET>.
My ~/etc/perforce/conf file looks like:
P4CLIENT=ewarmenhoven-ppd
P4PORT=perforce.netflix.com:1666
P4USER=ewarmenhoven
P4EDITOR=emacsclient
P4DIFF=diff -dupU8
P4MERGE=~/bin/emerge
The emerge merge program is just a short little shell script that calls emacsclient appropriately:
#!/bin/bash
base=$1
sccs=$2
mine=$3
merg=$4
emacsclient -e "(ediff-merge-files-with-ancestor \"$base\" \"$sccs\" \"$mine\" () \"$merg\")"
emacsclient "$merg"
If you're using cygwin it should work just fine.
For doing diffs, if it's running from the shell then I want the output in the shell, hence just using normal diff. If it's not, I use p4-ediff, which is bound to C-x p - by default.
The awesome answer by Eric doesn't work properly in latest emacs because of welcome screen. In order to hide the welcome screen (so that you may get the diff properly) please refer Unable to hide welcome screen in Emacs.
Another nifty setting which opens the diff in regular vertical mode is setting the below config variable
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(ediff-split-window-function (quote split-window-horizontally)))