Function: robot-mode-indent-line
robot-mode-indent-line is an interactive and natively compiled
function defined in robot-mode.el.
Signature
(robot-mode-indent-line)
Documentation
Indent current line in Robot mode.
Used as indent-line-function of the mode.
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/2wci9ylra7w4lc4cczbdr19c98f107vr-emacs-packages-deps/share/emacs/site-lisp/elpa/robot-mode-20240721.1023/robot-mode.el
(defun robot-mode-indent-line ()
"Indent current line in Robot mode.
Used as `indent-line-function' of the mode."
(interactive)
(let* ((indent 0)
;; Get the current section
(section
(downcase (or (save-excursion
(re-search-backward "^\\s-*\\*+\\s-*\\([a-zA-Z ]+\\)" nil t)
(match-string-no-properties 1)) "")))
;; The non-indented contents of previous non-empty line
previous-line
;; The amount of indent of previous non-empty line
(previous-indent
(save-excursion
(robot-mode--back-to-previous-line)
(setq previous-line (buffer-substring-no-properties
(point) (line-end-position)))
(current-indentation)))
;; The non-indented contents of the current line
current-line
;; The indentation level of the current line
(current-indent
(save-excursion
(back-to-indentation)
(setq current-line (buffer-substring-no-properties
(point) (line-end-position)))
(current-indentation))))
(setq indent
(cond ((or
;; Don't indent if not in the below sections
(not (string-match "task.*\\|test case.*\\|keyword.*" section))
;; Don't indent the section line
(string-match "^\\*" current-line)
;; Don't indent the line after a section line
(string-match "^\\*" previous-line))
0)
;; If the current line contains an inline IF, don't increase indent
((string-match "^\\s-*IF\\s-\\{2,\\}[^[:space:]]+\\s-\\{2,\\}[^#[:space:]]" previous-line)
previous-indent)
;; If previous line contains control structures, increase the
;; indentation level
((string-match "^\\s-*\\(IF\\|ELSE IF\\|ELSE\\|FOR\\|WHILE\\|TRY\\|EXCEPT\\|FINALLY\\)\\(\\s-\\{2,\\}.*\\|\\s-*$\\)" previous-line)
(+ previous-indent robot-mode-basic-offset))
;; Decrease indentation on control structures that end a block
((string-match"\\(END\\|ELSE IF\\|ELSE\\|EXCEPT\\|FINALLY\\)" current-line)
(max robot-mode-basic-offset (- previous-indent robot-mode-basic-offset)))
;; If previous line is indented, indent to that level
((> previous-indent 0)
previous-indent)
;; Otherwise indent to basic offset
(t
robot-mode-basic-offset)))
;; Toggle indentation if the line is already indented
(when (and robot-mode-indent-toggle
(> indent 0)
(= indent current-indent)
;; Prevent toggling if point is retained, TAB also does
;; completion, point is after indentation and previous command
;; was also an indentation.
(not (and robot-mode-retain-point-on-indent
(eq tab-always-indent 'complete)
(> (current-column) current-indent)
(equal this-command last-command))))
(setq indent 0))
(when (not robot-mode-retain-point-on-indent)
(back-to-indentation))
;; Save point if point retention is enabled and point is after indentation
(if (and (> (current-column) current-indent)
robot-mode-retain-point-on-indent)
(save-excursion
(indent-line-to indent))
(indent-line-to indent))))