I work in doom-emacs with LSP-metals(scala LSP client).
My inconvenience is when I execute action I need additional action saving the buffer to trigger LSP-server for recompilation and show an updated errors list.
For example, import needed class
I've tried to add the hook to lsp-execute-code-action but without success.
(add-hook 'lsp--execute-code-action 'save-current-buffer)
Related
I'm experimenting with the transition from Vim to Emacs, and one of Vim's features that I really miss is the context-insensitve completion popup (CTRL-n and CTRL-p). For example, in the buffer below, if I were to type he then CTRL-n, I would get a popup:
How can I get a similar context-insensitive completion menu in Emacs?
Note: I specifically want context-insensitive because it's often helpful to make references across different contexts (for example, reference a Python class from Restructured Text documentation) — something context-sensitive "omnicomplete" doesn't do.
Additionally, I know that M-/ will trigger auto-completion, but it only cycles through matches; I want a popup list showing matches.
Auto Complete Mode should do what you're looking for.
It's generally not triggered by a hotkey, but something like:
(setq ac-auto-start nil)
(global-set-key "\M-/" 'auto-complete)
should do what you want.
Auto Complete Mode shows a dropdown menu with matches: http://cx4a.org/software/auto-complete/manual.html#Basic_Usage
You can install it via the Marmalade repository: http://marmalade-repo.org/, follow the instructions to setup Marmalade, then M-x package-install auto-complete. You'll have to activate auto-complete-mode, then while typing anything it will show you matches (you can also force it by pressing TAB, by default).
I am already aware of the user-defined ignored packages setting in SublimeText2. Is there a way to modify this plugin -- e.g., with a keymap assignment -- to activate or deactivate this useful autosave feature? Perhaps chaining a plugin to the package control enable / disable feature, and assigning a keymap?
Here is the link to where I first discovered this plugin: Is there a way to autosave on each keystroke in sublime?
import sublime, sublime_plugin
class SaveOnModifiedListener(sublime_plugin.EventListener):
def on_modified(self, view):
view.run_command("save")
You can do this without relying on the package control commands. I can give you the answer, but I know you have been exploring writing plugins, so this might be a good exercise. It's pretty simple. Here are a couple hints though.
In the on modified command, you can check for a setting. You can give it a default value (I would do False) for if the setting does not exist. You can either write a text command to toggle the setting, or simply create a key binding with the toggle_setting command. Both will work, though if you write a command you can do something like create a status message so you know if save on modified is active or not. For information on toggle settings, see http://www.sublimetext.com/docs/2/settings.html.
If you just want the answer though, just let me know and I'll post it.
You can do this:
Go to Preferences -> Settings
Add the following line:
"save_on_focus_lost": true,
It would not automatically save the current file, however it would when you change the focus on other windows, Alt + Tab to terminal for example.
In my .emacs file I have (delete-selection-mode t) to enable the delete-selection-mode globally. Currently I'm working on a TeX file with AUXTeX, so it might be related to AUCTeX, but I don't know.
At first, after visiting a file foo.tex everything works fine, and typing over a marked text replaces the marked text with the one I type. However, after some time, during which I compile the document, add TeX macros, etc. the functionality of the delete-selection-mode doesn't work any more.
I don't know which action of mine is the one which causes the problem - it would be hard to trace it.
Note that although the functionality of the delete-selection-mode fails, when I try to enable it (M-x delete-selection-mode) I get a message that the mode was disabled! That is it was not disabled before - it just didn't work... I I then enable it (M-x delete-selection-mode again), then it is enabled and working again. Till the next fail...
Under the hood, the mode use pre-command-hook, which allows commands to run things right before every command. Emacs is known to clear this variable in the event of an error (just to make sure that Emacs don't hang). This mean that the function used by delete-selection-mode, or any other mode that use this hook, triggered an error.
How to fix it? Find what caused the error, wrap the function in a ignore-errors block, or run a timer re-adding the function every ten seconds or so.
I'm looking to run some code every time Emacs creates a buffer. Is there a hook for this? Something with a name like after-make-buffer-functions?
Edit: If anyone wants to know what I wanted this for, you can read the relevant portion of my Emacs config here: https://github.com/DarwinAwardWinner/dotemacs/blob/master/site-lisp/settings/tempbuf-settings.el
Basically, I want tempbuf-mode to be enabled in all buffers with certain major modes. So Lindydancer's answer is actually more appropriate than what I was originally looking for.
I know that I could already enable tempbuf-mode in specific modes by adding the tempbuf mode hook to all of those major mode hooks, but I wanted to make it editable through M-x customize, and this was the easiest way.
Unfortunately, no. Emacs use the low-level function ´get-buffer-create´ to create buffers, and it does not provide any hook mechanism.
You could use advice to pick-up all calls to this function, even though I would not recommend this method as it is quite intrusive. (Update: The advice hook will only see calls from elisp, not calls from the Emacs C core parts.)
There are some alternatives which you could use, depending on what you are implementing:
change-major-mode-hook -- called before a major mode change.
after-change-major-mode-hook -- called when the major mode is beginning to change.
You can use buffer-list-update-hook
buffer-list-update-hook
This is a normal hook run whenever the buffer list changes
You can define a function to do whatever you want.
(defun awesome-foo ()
;; do awesome things
)
Hook that function to buffer list hook
(add-hook 'buffer-list-update-hook 'awesome-foo)
I have just installed cedet (CVS version) and I am now playing with in emacs and my C++ source code.
Regarding the auto complete, I can invoke the tool tip and the menu from their semantic-ia-complete-* commands.
Does anyone know how I can make the auto complete tip appear automatically without my having to invoke a command (semantic-ia-complete-tip)? Is this even possible?
From CEDET website:
Automatically starting inline completion in idle time
M-x global-semantic-idle-completions-mode
This is a minor mode which runs
semantic-complete-analyze-inline-idle
during idle time. Instead of trying to
complete the symbol immediately, it
will just display the possible
completions, and underline the current
symbol the cursor is on.
In practice this means that the possible completions will appear whenever you stop typing and the cursor is under a symbol where completions are possible.
To use it, just put
(global-semantic-idle-completions-mode)
to your .emacs after loading the CEDET.