0

When wrapping save in a function so it always writes, (used so I can trigger compilation which I have set to watch my files).

(defun save-buffer-always ()
  "Save the buffer even if it is not modified."
  (interactive)
  (set-buffer-modified-p t)
  (save-buffer))

(global-set-key (kbd "C-s") 'save-buffer-always)

While this works, evil mode 'dot' operator now registers saving as an operation, so repeat-last (dot operator) doesn't repeat my last edit.

1

Evil stores and retrieves repeat information for commands to track whether and how they shall be repeated or whether they shouldn't. evil-declare-abort-repeat is the one used for save-buffer as seen in evil-integration.el:

(mapc #'evil-declare-abort-repeat
      '(balance-windows
        eval-expression
        execute-extended-command
        exit-minibuffer
        compile
        delete-window
        delete-other-windows
        find-file-at-point
        ffap-other-window
        recompile
        redo
        save-buffer
        split-window
        split-window-horizontally
        split-window-vertically
        undo
        undo-tree-redo
        undo-tree-undo))

You can therefore achieve the same effect for your own command with (evil-declare-abort-repeat 'save-buffer-always). Details on what the other repeat properties do can be found in evil-repeat.el.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.