Function: simula-electric-keyword
simula-electric-keyword is a byte-compiled function defined in
simula.el.gz.
Signature
(simula-electric-keyword)
Documentation
Expand SIMULA keyword. If it starts the line, reindent.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/simula.el.gz
(defun simula-electric-keyword ()
"Expand SIMULA keyword. If it starts the line, reindent."
;; redisplay
(let ((show-char (eq this-command 'self-insert-command)))
;; If the abbrev expansion results in reindentation, the user may have
;; to wait some time before the character he typed is displayed
;; (the char causing the expansion is inserted AFTER the hook function
;; is called). This is annoying in case of normal characters.
;; However, if the user pressed a key bound to newline, it is better
;; to have the line inserted after the begin-end match.
(if show-char
(progn
(insert-char last-command-event 1)
(sit-for 0)
(backward-char 1)))
(if (let ((where (simula-context))
(case-fold-search t))
(if where
(if (and (eq where 2) (eq (char-syntax (preceding-char)) ?w))
(save-excursion
(backward-word-strictly 1)
(not (looking-at "end\\>"))))))
(unexpand-abbrev)
(cond
((not simula-abbrev-keyword) (unexpand-abbrev))
((eq simula-abbrev-keyword 'upcase) (upcase-word -1))
((eq simula-abbrev-keyword 'downcase) (downcase-word -1))
((eq simula-abbrev-keyword 'capitalize) (capitalize-word -1)))
(let ((pos (- (point-max) (point)))
(case-fold-search t))
(condition-case nil
(progn
;; check if the expanded word is on the beginning of the line.
(if (and (eq (char-syntax (preceding-char)) ?w)
(progn
(backward-word-strictly 1)
(if (looking-at "end\\>")
(save-excursion
(simula-backward-up-level 1)
(if (pos-visible-in-window-p)
(sit-for 1)
(message "Matches %s"
(buffer-substring
(point)
(+ (point) (window-width)))))))
(skip-chars-backward " \t\f")
(bolp)))
(let ((indent (simula-calculate-indent)))
(if (eq indent (current-indentation))
()
(delete-horizontal-space)
(indent-to indent)))
(skip-chars-forward " \t\f"))
;; check for END - blow whistles and ring bells
(goto-char (- (point-max) pos))
(if show-char
(delete-char 1)))
(quit (goto-char (- (point-max) pos))))))))