How do I replace compile-internal with compilation start? - emacs

I use this valgrind.el to run valgrind inside emacs. But the newest version of emacs has deprecated compile-internal. I don't know nearly enough about elisp to figure out how to convert the compile-internal call to a compilation-start call. This is what the original function call in question looks like:
(compile-internal command "No more errors" "valgrind")
I found this bit online that indicates possible usage of compilation-start:
(compilation-start command mode
#'(lambda (mode-name) (concat "*" buf-name "*")))
Any help would be appreciated!

I am not sure about what you tried and what the results were.
As per the documentation, I would replace the compile internal line by:
(compilation-start command nil (lambda (mode-name) "*valgrind*"))

Related

I'm trying to shadow find-file in Emacs, why is this function yelling at me about arguments?

I'm a recent convert to Evil-mode from Vim and I'm trying to make the environment more familiar. One of the things I miss is the find command in Vim. I'm trying to set up something similar in Emacs by wrapping the find-file command in a function. So far I have this:
(defun find nil
"Shadow vim find command, with helm."
(interactive)
(find-file))
When I run the command it yells at me, Wrong number of arguments {doc string} 0 I've tried adding arguments and had no success. The really confusing bit is that I shadowed a helm function the same way and it worked, like this:
(defun buflist nil
"List buffers in helm."
(interactive)
(helm-buffers-list))
What's different? How do I fix this?
find-file takes a file name as argument, you will want to get familiar with C-h f to lookup up function documentation.
interactive can take arguments, for example,
(defun find (filename)
(interactive "F")
(find-file filename))
find-file needs arguments, you can't call it just like
(find-file)
The debugger shows what arguments are needed:
(filename &optional wildcards)
You can also invoke help to see them: C-hf.
Another option is to use call-interactively:
(call-interactively 'find-file)

Emacs setting up a temporary file directory

I'm trying to set up Emacs on my computer and have all backups in a temporary folder, with the following in my .emacs file:
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
However, I keep on getting the error:
Wrong type argument: stringp, (\, temporary-file-directory)
Which I think is an artefact of the \ / differences between Windows and Unix.
How do I go about stopping this?
Are you sure that you are using a backquote and not a quote? My guess would be that you have
(setq backup-directory-alist '((".*" . ,temporary-file-directory)))
instead of
(setq backup-directory-alist `((".*" . ,temporary-file-directory)))
I think you need to show more about the error context -- where it is raised etc. There is nothing wrong with the backquote sexp you show, AFAICT. And no relation, I expect, with differences between MS Windows and Unix. The question is how the resulting new values for those variables are used. IOW, check (a) whether the new values are what you intended, and if so (b) why they do not seem to be what the code that uses them expects.
Start by setting debug-on-error to t, to see where the error is raised and why. Load the *.el code for that file (defining the function where the error is raised) to improve the debugger backtrace.
But the complaint seems to come from the backquote-processing itself. What happens when you evaluate one of those setq sexps on its own, e.g. using M-: or buffer *scratch*? Do you get the error then? If not, what is the resulting new value of the variable?
Another thing to try, if you get the error even outside your .emacs, is to wrap your setq sexp in (macroexpand ...) and see what the result is.

Emacs desktop-save-mode startup error

After adding the following code in my .emacs file, comes up some error during startup of emacs. I am a newbie of emacs, is there some one can help me figure out where are the errors come from?
Added code in .emacs:
;; Auto-saving the Desktop
(require 'desktop)
(desktop-save-mode 1)
(defun my-desktop-save ()
(interactive)
;; Don't call desktop-save-in-desktop-dir, as it prints a message.
(if (eq (desktop-owner) (emacs-pid))
(desktop-save desktop-dirname)))
(add-hook 'auto-save-hook 'my-desktop-save)
Errors:
Looking at the function definition for what's breaking, it seems that the error is that prj-file is NIL in line 492. (The other expand-filename call in the function shouldn't ever have a nil, since it's the car of a non-nil list of filenames).
Now, prj-file is the first filename in /home/shenyan/Test/memcached-1.4.11 matching the regexp "\\(Root\\)?ProjStep.ede" and presumably there isn't one. Since memcached presumably doesn't have an EDE project file, what's gone wrong must be that line 508's call to ede-project-p did something weird when called with this subdirectory of /home/shenyan/Test/.
I can't work out exactly why that happened, but you can debug things quite easily. First bring up your *scratch* buffer to type emacs lisp easily. To check my guess, insert the following code into the buffer
(ede-directory-project-p "/home/shenyan/Test/memcached-1.4.11")
and run it by hitting C-x C-e with cursor on the closing bracket. If it returns nil I was wrong. Otherwise, you've found the culprit and should probably debug it further by hunting through the bits of ede-directory-project-p in ede-files.el.
Probably what's going on is that your /home/shenyan/Test/ directory has something that tells EDE to search subdirectories (or maybe that's the default?) and then the memcached subdirectory has a file whose name makes EDE think it should be searched for a project file. If you work out exactly what happened, you might consider submitting a bug to the EDE developers: they probably shouldn't error out if the project file doesn't exist.

Emacs ediff error "no newline at end of file"

On Debian Wheezy, Emacs 23.3.1, running ediff-files with a file that is missing a newline at the end results in the error \ No newline at end of file (I hope that's the correct translation; it's German \ Kein Zeilenumbruch am Dateiende. on my computer.)
Is it possible to have just a warning instead, so that I can see the diff and work on it (and fix the missing newline)? It's just a bit tedious to first have ediff fail, then open the file, add the newline, ediff again.
Try changing the value of the variable ediff-diff-ok-lines-regexp to include the German text ("Kein Zeilenumbruch am Dateiende"):
(setq ediff-diff-ok-lines-regexp
(concat
"^\\("
"[0-9,]+[acd][0-9,]+\C-m?$"
"\\|[] "
"\\|---"
"\\|.*Warning *:"
"\\|.*No +newline"
"\\|.*missing +newline"
"\\|.*Kein +Zeilenumbruch +am +Dateiende"
"\\|^\C-m?$"
"\\)"))
Update: Looking at the source code, it does seem that Ediff doesn't make any attempt to deal with the issue of localization of messages from diff. It should also be possible to work around this by wrapping diff in a shell script, e.g:
#!/bin/bash
LANG=C diff $*
..then customising the ediff-diff-program to call the wrapper instead:
(setq ediff-diff-program "~/bin/my-diff.sh")
Other code in the Emacs source directory lisp/vc does seem to handle this, for example vc-hg-state:
(defun vc-hg-state (file)
"Hg-specific version of `vc-state'."
...
(with-output-to-string
(with-current-buffer
standard-output
(setq status
(condition-case nil
;; Ignore all errors.
(let ((process-environment
;; Avoid localization of messages so we
;; can parse the output.
(append (list "TERM=dumb" "LANGUAGE=C")
process-environment)))
...
It seems a bit strange that Ediff doesn't also do this, but perhaps I'm missing something.
Ok, I found out what's wrong, and sadly, it's quite obvious: my environment has LANG=de, therefore when Emacs invokes diff, the warning message is returned in German as well, and Emacs, not recognising this “unkown” message, fails.
Starting emacs with LANG=C emacs works around this problem. However, I consider it a (quite silly) bug of emacs to make assumption on the user's language being English.

emacs ( recompile -y )

Is it possible to pass a "-yes" flag to the 'recompile' command in emacs?
Excuse my complete lack of (e)lisp know-how. I got sick of going outside Emacs to compile my latex code, so i added the following key binding to my .emacs:
(global-set-key (kbd "<f12>") 'recompile);
Is it possible to automatically answer 'yes' to the following prompt that might appear:
"A compilation process is running; kill it? (yes or no)."
Also, is it possible to make the window that opens and shows the output to scroll to the bottom automatically. The interesting stuff is typically down there. Maybe its possible to chain the following command after recompile: "C-x o, end-of-buffer".
Thanks!
Here's some code to solve your first problem (interrupting the current compilation):
(defun interrupt-and-recompile ()
"Interrupt old compilation, if any, and recompile."
(interactive)
(ignore-errors (kill-compilation))
(recompile))
For your second problem (scrolling the compilation output), just customize the user setting compilation-scroll-output.
This behaviour is governed by the compilation-always-kill global variable. Customize it via customize-variable and set it to t.
Not sure which version of emacs first had this, but 26 and newer certainly does.
I somehow need to put kill-compilation into a ignore-errors with Emacs 23.2 to get it to work when no process is running. Otherwise works great.
(defun interrupt-and-recompile ()
"Interrupt old compilation, if any, and recompile."
(interactive)
(ignore-errors
(kill-compilation))
(recompile)
)
Whenever I tried using kill-compilation with latex/pdflatex it did not work. I assume it is because latex does not respond to SIGINT.
Instead I am using the following hack, which first sets the process-kill-without-query bit of the compilation-buffer and then closes it (which kills the running process).
(defun interrupt-and-recompile ()
"Interrupt old compilation, if any, and recompile."
(interactive)
(ignore-errors
(process-kill-without-query
(get-buffer-process
(get-buffer "*compilation*"))))
(ignore-errors
(kill-buffer "*compilation*"))
(recompile)
)
The other solutions didn't work for me for the same reason as sfeuz, but I didn't like the nuclear option of killing the hardcoded buffer by name.
Here's a short solution that autoanswers yes to that specific question by advising yes-or-no-p:
ftp://download.tuxfamily.org/user42/compilation-always-kill.el
(source: http://www.emacswiki.org/CompilationMode)