Created
June 12, 2023 21:35
-
-
Save dhellmann/658a1c77f9109fb446c71588783dd858 to your computer and use it in GitHub Desktop.
emacs settings for robot-mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package robot-mode | |
:ensure t | |
:init | |
) | |
;; ensure that *.resource files are treated as robot framework files | |
(setq auto-mode-alist | |
(cons '("\\.resource$" . robot-mode) auto-mode-alist)) | |
;; based on https://www.masteringemacs.org/article/executing-shell-commands-emacs | |
(defun rf-tidy-buffer () | |
(interactive) | |
;; save-excursion breaks because we replace the buffer content so we | |
;; lose the mark. Saving the character we are no does not work | |
;; because we are likely to see a lot of new characters inserted | |
;; when reformatting. There are fewer lines added or removed, so | |
;; remember which line we are on and jump back to that spot | |
;; ourself. count-lines tells us how many lines are before the line | |
;; we are on, so to get back to the current line we have to add 1. | |
(when (executable-find "robotidy") | |
(setq rf-tidy-saved-position (1+ (count-lines (point-min) (point)))) | |
(shell-command-on-region | |
;; whole buffer | |
(point-min) (point-max) | |
;; shell command | |
"robotidy -" | |
;; output buffer | |
(current-buffer) | |
;; replace? | |
t | |
;; name of the error buffer | |
"*robotidy Error Buffer*" | |
;; show error buffer? | |
t | |
) | |
(goto-line rf-tidy-saved-position) | |
) | |
) | |
(defun rf-tidy-before-save () | |
(interactive) | |
(when (eq major-mode 'robot-mode) | |
(condition-case err (rf-tidy-buffer) | |
(error (message "%s" (error-message-string err)))))) | |
(add-hook 'before-save-hook 'rf-tidy-before-save) | |
(add-hook 'robot-mode-hook | |
(lambda () | |
(setq tab-width 4) | |
(setq indent-tabs-mode nil) | |
(linum-mode) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment