InertiaOfGravity · 2022-07-09 17:48
I'm using spacemacs, and to circumvent an issue with flycheck not updating errors automatically, I want to have a single sequence that both saves a file (writes the buffer to the loaded file) and reloads that file into the buffer. I'm really new to Emacs and have no idea where to even begin setting something like this up. Any/all help greatly appreciated
0xMii · 2022-07-09 17:54
(defun save-and-reload ()
“Save and reload buffer.”
(interactive)
(save-buffer)
(revert-buffer :ignore-auto :noconfirm))
This should do what you want, I believe.
Chaining commands is really just making a new function that calls the other functions. With `(interactive)` you make sure it shows up in `M-x`.
rswgnu · 2022-07-09 18:21
Interactively, look up keyboard macros to do what you want, so you can create your own patterns of commands.
InertiaOfGravity · 2022-07-10 04:08
How can I bind this to a sequence?
0xMii · 2022-07-10 09:08
(global-set-key (kbd “C-x C-s”)
#’save-and-reload)
Replace `C-x C-s` with whatever key sequence you want.
If you only want this in some modes, take a look at key maps.
BunnyLushington · 2022-07-10 14:09
Although the answer you received answered your question, I'd suggest that this is a nice situation to use a hook. They're useful beasts.
`(add-hook 'after-save-hook`
`(lambda () (revert-buffer :ignore-auto :noconfirm)))`
arthurno1 · 2022-07-10 23:41
> to circumvent an issue with flycheck not updating errors automatically,
Which issue? Have you checked [the manual when flycheck does error-checking](https://www.flycheck.org/en/latest/user/syntax-checks.html)? (on save, on inserting new line, on flycheck mode enabled and on idle timer).
> I want to have a single sequence that both saves a file (writes the buffer to the loaded file) and reloads that file into the buffer
What you are doing here is triggering flycheck when mode is enabled (since you are reverting the buffer), so you could just have a script to turn off/on flycheck mode without saving and reverting. But have you tested to configure idle-change to a shorter interval as suggested in the manual? The proper way seem to be via idle timer, you should not need to turn off/on the mode itself.
Another option could to add an [after change hook](https://www.gnu.org/software/emacs/manual/html_node/elisp/Change-Hooks.html), test for space and call error-check for the last word when space is inserted, or some other predicate you find useful.
InertiaOfGravity · 2022-07-11 03:54
When I write using spacemacs \`:w\` it doesn't seem to update
I understood nothing after the second time you quoted me
InertiaOfGravity · 2022-07-11 03:57
So hooks run code after some action is complete right? Would this still work with \`:w\` from evil?
WallyMetropolis · 2022-07-15 14:47
[This recent post](https://masteringemacs.org/article/keyboard-macros-are-misunderstood) is a great starting place for using keyboard macros. For OP, basically the idea is that you can record some actions you take and replay that recording at any time. You can give that recording a name and call it like any other function, and you can save it in your init so it will be available in future emacs sessions.