Emacs: ac-slime for auto complete - emacs

I am trying to add auto complete for *.lisp files. My slime setting is:
(add-to-list 'load-path "~/.emacs.d/plugins/slime/")
(setq slime-lisp-implementations
'((sbcl ("/opt/sbcl/bin/sbcl" "--core" "/opt/sbcl/lib/sbcl/sbcl.core")
:coding-system utf-8-unix
:env ("SBCL_HOME=/opt/sbcl/lib/sbcl"))
(ccl ("/opt/ccl/lx86cl64")
:coding-system utf-8-unix)))
(require 'slime-autoloads)
(slime-setup '(slime-fancy))
And ac-slime setting is:
(require 'ac-slime)
(add-hook 'slime-mode-hook 'set-up-slime-ac)
(add-hook 'slime-repl-mode-hook 'set-up-slime-ac)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'slime-repl-mode))
Each time I type a word in *.lisp file, auto complete popups some candidates but after a second minibuffer outputs
error in process filter: Reply to canceled synchronous eval request
tag=slime-result-6-19579
sexp=(swank:simple-completions "de" (quote "COMMON-LISP-USER"))
and the popup stuck for a while. After that I can continue my selection.
My question is how to remove this error and stuck? Any help is appreciated.

(this is too long for a comment)
I don't know yet how all this work but I had the same issue and I can always reproduce it... And I found a workaround.
I don't know what "Reply to canceled synchronous eval request" means nor if there are really two synchronous eval requests.
And in case there are two such requests, I don't know what is causing them...
However by changing the timer before which the auto-completion menu and pop-up show up, I've been able to work around the issue.
If I eval this (say from my .emacs file):
(setq ac-auto-show-menu 0.1)
then I can reliably reproduce the error you have (and it blocks a while for me too).
If I modify the value a bit:
(setq ac-auto-show-menu 0.3)
Then there's no issue anymore.
It's a crappy workaround and I still think there's a serious (although maybe easy to fix) underlying bug hiding somewhere.

Related

emacs suggests to recover-file, but I missed it: how to make it prompt?

When emacs notices a crash, on next open of the file it "suggests" M-x recover file. But that only flashes up briefly, so I missed it this morning :( I went on editing, and lost last evening's work.
Is there a way to make that suggestion a prompt that must be responded to before it continues?
The warning message comes from the function after-find-file. I don't find an option to control this, but you can define a function to do something similar:
(defvar already-in-prompt-for-auto-save nil)
(defun prompt-for-auto-save-recovery ()
(if (and (not buffer-read-only)
(not already-in-prompt-for-auto-save)
(file-newer-than-file-p (or buffer-auto-save-file-name
(make-auto-save-file-name))
buffer-file-name)
(y-or-n-p (format "%s has auto save data: do you want to recover it? "
(file-name-nondirectory buffer-file-name))))
(let ((already-in-prompt-for-auto-save t))
(recover-this-file))))
and then install it as a hook.
(add-hook 'find-file-hook 'prompt-for-auto-save-recovery)
This is lightly tested code--I extracted what looked like the relevant parts of after-find-file--but maybe it will get you started in the right direction.

display flycheck buffer automatically when there are errors

I'd like for the flycheck buffer to be automatically displayed when there are (flycheck detected) errors in the buffer I'm currently editing. My assumption is that this would best be done by checking that (flycheck-current-errors) returns true.
Does anyone know of any existing setting or elisp code that would enable this?
If there isn't anything existing I guess I'll try to write something up, probably following an approach similar to the code in this question Display Flycheck buffer (with errors) when saving but I'll need to figure out a good hook point to run the check just frequently enough to be useful but not add too much background overhead.
based on the suggestion from #gdkrmr above (Thanks!), I coded up the following which does what I want:
(add-hook 'flycheck-after-syntax-check-hook
(lambda ()
(if flycheck-current-errors
(flycheck-list-errors)
(when (get-buffer "*Flycheck errors*")
(switch-to-buffer "*Flycheck errors*")
(kill-buffer (current-buffer))
(delete-window)))))

Don't display *compilation* buffer in Emacs until the process exits with error or warning

I am looking for a way to have the Emacs compilation buffer triggered by M-x compile, M-x recompile or some compile on save script only appear when the compilation exits either with an error or a warning.
Note that I am not looking for a way to close the compile buffer if there are no errors or warnings as described in [1]. No I want the buffer to never appear until the compilation is fully finished and only appear if there is an error or warning to display.
The reasons are simple: The flickering compile buffer is disturbing and rearranges the position of the code on the screen. This becomes more annoying if you have compile on save turned on.
The compile buffer contains many different types of compile processes from make to pdflatex so it would be great if the function which determines whether the buffer should be displayed works across the board.
[1] emacs compile buffer auto close?
Looks like you can achieve what you want through temporarily disabling display-buffer across compilation-start.
This is a combination of what sds said and something posted on the comments # here
The comment there had a nasty problem with point jumping in the original source buffer that I appear to have worked out by also blocking set-window-point and goto-char. It feels like a dirty hack, but is working so far. YMMV!
(defun brian-compile-finish (buffer outstr)
(unless (string-match "finished" outstr)
(switch-to-buffer-other-window buffer))
t)
(setq compilation-finish-functions 'brian-compile-finish)
(require 'cl)
(defadvice compilation-start
(around inhibit-display
(command &optional mode name-function highlight-regexp))
(if (not (string-match "^\\(find\\|grep\\)" command))
(flet ((display-buffer)
(set-window-point)
(goto-char))
(fset 'display-buffer 'ignore)
(fset 'goto-char 'ignore)
(fset 'set-window-point 'ignore)
(save-window-excursion
ad-do-it))
ad-do-it))
(ad-activate 'compilation-start)
Now you should see that all compile buffers will only be shown if outstr doesn't return a successful finish status OR the invoked command started with "find" or "grep."
I edited #assem's answer to use cl-letf instead of flet.
(defun brian-compile-finish (buffer outstr)
(unless (string-match "finished" outstr)
(switch-to-buffer-other-window buffer))
t)
(setq compilation-finish-functions 'brian-compile-finish)
(defadvice compilation-start
(around inhibit-display
(command &optional mode name-function highlight-regexp))
(if (not (string-match "^\\(find\\|grep\\)" command))
(cl-letf ((display-buffer #'ignore)
(set-window-point #'ignoreco)
(goto-char #'ignore))
(save-window-excursion
ad-do-it))
ad-do-it))
(ad-activate 'compilation-start)
(provide 'only-display-compile-on-error)
The function compilation-start calls display-buffer on the compilation buffer. This should give you all the control you need.
I.e., you need to customize one of the action variables (display-buffer-overriding-action et al) so that it will handle compilation buffers specially buy displaying it in a separate frame and not displaying the frame itself.
Then you need to customize your compilation-filter-hook so that, whenever a warning or an error is inserted into the compilation buffer, the compilation buffer is displayed visibly (e.g., by popping up the aforementioned separate frame). Don't forget to bind your action variable to nil there!
assems answer has been overtaken by events, somewhat.
Emacs core, in their wisdom have decided to deprecate flet.
The suggested alternative is cl-flet. However, as discussed in this post, this seems to be lexically scoped rather than dynamically scoped. We explicitly want dynamic scoping.
Should `flet` be replaced with `cl-flet` or `cl-letf` ?
This page suggests replace flet to noflet, a third-party library.
This appears to only support the definition of functions and their bodies.
So the flet in assem's answer becomes
(noflet ((display-buffer ()) ....

Forcing haskell-indent-mode over haskell-indentation-mode in haskell-mode 2.7?

I'm an Emacs user with no skills with regards to configuring the editor. After I upgraded from haskell-mode 2.4 to 2.7, I've noticed two changes:
Indentation is different somehow, in a way I don't quite like. I can't quite put my finger on what it is.
More importantly: If I have cua-mode enabled and highlight a block of text, backspace/delete does not delete the entire block, just the previous/next character from my marker.
I see that haskell-mode 2.7 uses the minor mode haskell-indentation-mode by default, while 2.4's behaviour has been preserved in the form of haskell-indent-mode. If I first turn off the former, and then on the latter, the behaviour I want is restored (i.e. indentation feels like before, and backspace/delete deletes highlighted blocks).
I can't, however, get this to happen automatically whenever I open a file with a .hs suffix. I've tried various things resembling
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent-mode)
and the likes of it, but I either end up with the standard mode or with plain haskell-mode without indent and doc.
Any ideas?
Solution (thanks to nominolo):
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
)
The best way to configure such things is by writing a custom hook:
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
;; further customisations go here. For example:
(setq locale-coding-system 'utf-8 )
(flyspell-prog-mode) ;; spell-checking in comments and strings
;; etc.
)
You could also stick an anonymous function in there, but having a named function is easier if you want to experiment with some settings. Just redefining the function (and re-opening a Haskell file) will give you the new behaviour.

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)