home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / contrib / emacs / iconmode.txt < prev   
Internet Message Format  |  1994-12-26  |  20KB

  1. From icon-group-sender Thu Dec 22 05:44:38 1994
  2. Received: by cheltenham.cs.arizona.edu; Thu, 22 Dec 1994 05:43:45 MST
  3. Date: Thu, 22 Dec 1994 06:43:19 -0600
  4. From: jeffery@runner.jpl.utsa.edu (Clinton L. Jeffery)
  5. Message-Id: <9412221243.AA03475@runner.utsa.edu>
  6. To: abrahams@equinox.ShaysNet.COM
  7. Cc: icon-group@cs.arizona.edu
  8. In-Reply-To: <9412220403.AA06292@equinox.shaysnet.com> (abrahams@equinox.ShaysNet.COM)
  9. Subject: Re: Where is icon-mode.el for Emacs?
  10. Content-Length: 19913
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: R
  13.  
  14. I was under the impression that GNU emacs came with an icon-mode.el
  15. At least, I know *I* didn't have to write one.
  16. Here's what I've been using; its hacked a bit from the real one.
  17.  
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;; Icon code editing commands for Emacs
  20. ;; Derived from c-mode.el  15-Apr-88  Chris Smith  convex!csmith
  21. ;; Copyright (C) 1988 Free Software Foundation, Inc.
  22.  
  23. ;; This file is part of GNU Emacs.
  24.  
  25. ;; GNU Emacs is distributed in the hope that it will be useful,
  26. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  27. ;; accepts responsibility to anyone for the consequences of using it
  28. ;; or for whether it serves any particular purpose or works at all,
  29. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  30. ;; License for full details.
  31.  
  32. ;; Everyone is granted permission to copy, modify and redistribute
  33. ;; GNU Emacs, but only under the conditions described in the
  34. ;; GNU Emacs General Public License.   A copy of this license is
  35. ;; supposed to have been given to you along with GNU Emacs so you
  36. ;; can know your rights and responsibilities.  It should be in a
  37. ;; file named COPYING.  Among other things, the copyright notice
  38. ;; and this notice must be preserved on all copies.
  39.  
  40. (provide 'icon-mode)
  41.  
  42. (defvar icon-mode-abbrev-table nil
  43.   "Abbrev table in use in Icon-mode buffers.")
  44. (define-abbrev-table 'icon-mode-abbrev-table ())
  45.  
  46. (defvar icon-mode-map ()
  47.   "Keymap used in Icon mode.")
  48. (if icon-mode-map
  49.     ()
  50.   (setq icon-mode-map (make-sparse-keymap))
  51.   (define-key icon-mode-map "{" 'electric-icon-brace)
  52.   (define-key icon-mode-map "}" 'electric-icon-brace)
  53.   (define-key icon-mode-map "\e\C-h" 'mark-icon-function)
  54.   (define-key icon-mode-map "\e\C-a" 'beginning-of-icon-defun)
  55.   (define-key icon-mode-map "\e\C-e" 'end-of-icon-defun)
  56.   (define-key icon-mode-map "\e\C-q" 'indent-icon-exp)
  57.   (define-key icon-mode-map "\177" 'backward-delete-char-untabify)
  58.   (define-key icon-mode-map "\t" 'icon-indent-command))
  59.  
  60. (defvar icon-mode-syntax-table nil
  61.   "Syntax table in use in Icon-mode buffers.")
  62.  
  63. (if icon-mode-syntax-table
  64.     ()
  65.   (setq icon-mode-syntax-table (make-syntax-table))
  66.   (modify-syntax-entry ?\\ "\\" icon-mode-syntax-table)
  67.   (modify-syntax-entry ?# "<" icon-mode-syntax-table)
  68.   (modify-syntax-entry ?\n ">" icon-mode-syntax-table)
  69.   (modify-syntax-entry ?$ "." icon-mode-syntax-table)
  70.   (modify-syntax-entry ?/ "." icon-mode-syntax-table)
  71.   (modify-syntax-entry ?* "." icon-mode-syntax-table)
  72.   (modify-syntax-entry ?+ "." icon-mode-syntax-table)
  73.   (modify-syntax-entry ?- "." icon-mode-syntax-table)
  74.   (modify-syntax-entry ?= "." icon-mode-syntax-table)
  75.   (modify-syntax-entry ?% "." icon-mode-syntax-table)
  76.   (modify-syntax-entry ?< "." icon-mode-syntax-table)
  77.   (modify-syntax-entry ?> "." icon-mode-syntax-table)
  78.   (modify-syntax-entry ?& "." icon-mode-syntax-table)
  79.   (modify-syntax-entry ?| "." icon-mode-syntax-table)
  80.   (modify-syntax-entry ?\' "\"" icon-mode-syntax-table))
  81.  
  82. ; this used to be 4
  83. (defconst icon-indent-level 3
  84.   "*Indentation of Icon statements with respect to containing block.")
  85. (defconst icon-brace-imaginary-offset 0
  86.   "*Imagined indentation of a Icon open brace that actually follows a statement.")
  87. (defconst icon-brace-offset 3
  88.   "*Extra indentation for braces, compared with other text in same context.")
  89. ; this used to be 4
  90. (defconst icon-continued-statement-offset 3
  91.   "*Extra indent for lines not starting new statements.")
  92. (defconst icon-continued-brace-offset 0
  93.   "*Extra indent for substatements that start with open-braces.
  94. This is in addition to icon-continued-statement-offset.")
  95.  
  96. (defconst icon-auto-newline nil
  97.   "*Non-nil means automatically newline before and after braces,
  98. and after colons and semicolons, inserted in C code.")
  99.  
  100. (defconst icon-tab-always-indent t
  101.   "*Non-nil means TAB in Icon mode should always reindent the current line,
  102. regardless of where in the line point is when the TAB command is used.")
  103.  
  104. (defun icon-mode ()
  105.   "Major mode for editing Icon code.
  106. Expression and list commands understand all Icon brackets.
  107. Tab indents for Icon code.
  108. Paragraphs are separated by blank lines only.
  109. Delete converts tabs to spaces as it moves back.
  110. \\{icon-mode-map}
  111. Variables controlling indentation style:
  112.  icon-tab-always-indent
  113.     Non-nil means TAB in Icon mode should always reindent the current line,
  114.     regardless of where in the line point is when the TAB command is used.
  115.  icon-auto-newline
  116.     Non-nil means automatically newline before and after braces
  117.     inserted in Icon code.
  118.  icon-indent-level
  119.     Indentation of Icon statements within surrounding block.
  120.     The surrounding block's indentation is the indentation
  121.     of the line on which the open-brace appears.
  122.  icon-continued-statement-offset
  123.     Extra indentation given to a substatement, such as the
  124.     then-clause of an if or body of a while.
  125.  icon-continued-brace-offset
  126.     Extra indentation given to a brace that starts a substatement.
  127.     This is in addition to icon-continued-statement-offset.
  128.  icon-brace-offset
  129.     Extra indentation for line if it starts with an open brace.
  130.  icon-brace-imaginary-offset
  131.     An open brace following other text is treated as if it were
  132.     this far to the right of the start of its line.
  133.  
  134. Turning on Icon mode calls the value of the variable icon-mode-hook with no args,
  135. if that value is non-nil."
  136.   (interactive)
  137.   (kill-all-local-variables)
  138.   (use-local-map icon-mode-map)
  139.   (setq major-mode 'icon-mode)
  140.   (setq mode-name "Icon")
  141.   (setq local-abbrev-table icon-mode-abbrev-table)
  142.   (set-syntax-table icon-mode-syntax-table)
  143.   (make-local-variable 'paragraph-start)
  144.   (setq paragraph-start (concat "^$\\|" page-delimiter))
  145.   (make-local-variable 'paragraph-separate)
  146.   (setq paragraph-separate paragraph-start)
  147.   (make-local-variable 'indent-line-function)
  148.   (setq indent-line-function 'icon-indent-line)
  149.   (make-local-variable 'require-final-newline)
  150.   (setq require-final-newline t)
  151.   (make-local-variable 'comment-start)
  152.   (setq comment-start "# ")
  153.   (make-local-variable 'comment-end)
  154.   (setq comment-end "")
  155.   (make-local-variable 'comment-column)
  156.   (setq comment-column 32)
  157.   (make-local-variable 'comment-start-skip)
  158.   (setq comment-start-skip "# *")
  159.   (make-local-variable 'comment-indent-hook)
  160.   (setq comment-indent-hook 'icon-comment-indent)
  161.   (run-hooks 'icon-mode-hook))
  162.  
  163. ;; This is used by indent-for-comment
  164. ;; to decide how much to indent a comment in Icon code
  165. ;; based on its context.
  166. (defun icon-comment-indent ()
  167.   (if (looking-at "^#")
  168.       0                ;Existing comment at bol stays there.
  169.     (save-excursion
  170.       (skip-chars-backward " \t")
  171.       (max (1+ (current-column))    ;Else indent at comment column
  172.        comment-column))))    ; except leave at least one space.
  173.  
  174. (defun electric-icon-brace (arg)
  175.   "Insert character and correct line's indentation."
  176.   (interactive "P")
  177.   (let (insertpos)
  178.     (if (and (not arg)
  179.          (eolp)
  180.          (or (save-excursion
  181.            (skip-chars-backward " \t")
  182.            (bolp))
  183.          (if icon-auto-newline
  184.              (progn (icon-indent-line) (newline) t)
  185.            nil)))
  186.     (progn
  187.       (insert last-command-char)
  188.       (icon-indent-line)
  189.       (if icon-auto-newline
  190.           (progn
  191.         (newline)
  192.         ;; (newline) may have done auto-fill
  193.         (setq insertpos (- (point) 2))
  194.         (icon-indent-line)))
  195.       (save-excursion
  196.         (if insertpos (goto-char (1+ insertpos)))
  197.         (delete-char -1))))
  198.     (if insertpos
  199.     (save-excursion
  200.       (goto-char insertpos)
  201.       (self-insert-command (prefix-numeric-value arg)))
  202.       (self-insert-command (prefix-numeric-value arg)))))
  203.  
  204. (defun icon-indent-command (&optional whole-exp)
  205.   (interactive "P")
  206.   "Indent current line as Icon code, or in some cases insert a tab character.
  207. If icon-tab-always-indent is non-nil (the default), always indent current line.
  208. Otherwise, indent the current line only if point is at the left margin
  209. or in the line's indentation; otherwise insert a tab.
  210.  
  211. A numeric argument, regardless of its value,
  212. means indent rigidly all the lines of the expression starting after point
  213. so that this line becomes properly indented.
  214. The relative indentation among the lines of the expression are preserved."
  215.   (if whole-exp
  216.       ;; If arg, always indent this line as Icon
  217.       ;; and shift remaining lines of expression the same amount.
  218.       (let ((shift-amt (icon-indent-line))
  219.         beg end)
  220.     (save-excursion
  221.       (if icon-tab-always-indent
  222.           (beginning-of-line))
  223.       (setq beg (point))
  224.       (forward-sexp 1)
  225.       (setq end (point))
  226.       (goto-char beg)
  227.       (forward-line 1)
  228.       (setq beg (point)))
  229.     (if (> end beg)
  230.         (indent-code-rigidly beg end shift-amt "#")))
  231.     (if (and (not icon-tab-always-indent)
  232.          (save-excursion
  233.            (skip-chars-backward " \t")
  234.            (not (bolp))))
  235.     (insert-tab)
  236.       (icon-indent-line))))
  237.  
  238. (defun icon-indent-line ()
  239.   "Indent current line as Icon code.
  240. Return the amount the indentation changed by."
  241.   (let ((indent (calculate-icon-indent nil))
  242.     beg shift-amt
  243.     (case-fold-search nil)
  244.     (pos (- (point-max) (point))))
  245.     (beginning-of-line)
  246.     (setq beg (point))
  247.     (cond ((eq indent nil)
  248.        (setq indent (current-indentation)))
  249.       ((eq indent t)
  250.        (setq indent (calculate-icon-indent-within-comment)))
  251. ;      ((looking-at "[ \t]*#")
  252. ;       (setq indent 0))
  253.       (t
  254.        (skip-chars-forward " \t")
  255.        (if (listp indent) (setq indent (car indent)))
  256.        (cond ((and (looking-at "else\\b")
  257.                (not (looking-at "else\\s_")))
  258.           (setq indent (save-excursion
  259.                  (icon-backward-to-start-of-if)
  260.                  (current-indentation))))
  261. ;;;         ((or (= (following-char) ?})
  262. ;;;              (looking-at "end\\b"))
  263.          ((looking-at "end\\b")
  264.           (setq indent (- indent icon-indent-level)))
  265.          ((= (following-char) ?{)
  266.           (setq indent (+ indent icon-brace-offset))))))
  267.     (skip-chars-forward " \t")
  268.     (setq shift-amt (- indent (current-column)))
  269.     (if (zerop shift-amt)
  270.     (if (> (- (point-max) pos) (point))
  271.         (goto-char (- (point-max) pos)))
  272.       (delete-region beg (point))
  273.       (indent-to indent)
  274.       ;; If initial point was within line's indentation,
  275.       ;; position after the indentation.  Else stay at same point in text.
  276.       (if (> (- (point-max) pos) (point))
  277.       (goto-char (- (point-max) pos))))
  278.     shift-amt))
  279.  
  280. (defun calculate-icon-indent (&optional parse-start)
  281.   "Return appropriate indentation for current line as Icon code.
  282. In usual case returns an integer: the column to indent to.
  283. Returns nil if line starts inside a string, t if in a comment."
  284.   (save-excursion
  285.     (beginning-of-line)
  286.     (let ((indent-point (point))
  287.       (case-fold-search nil)
  288.       state
  289.       containing-sexp
  290.       toplevel)
  291.       (if parse-start
  292.       (goto-char parse-start)
  293.     (setq toplevel (beginning-of-icon-defun)))
  294.       (while (< (point) indent-point)
  295.     (setq parse-start (point))
  296.     (setq state (parse-partial-sexp (point) indent-point 0))
  297.     (setq containing-sexp (car (cdr state))))
  298.       (cond ((or (nth 3 state) (nth 4 state))
  299.          ;; return nil or t if should not change this line
  300.          (nth 4 state))
  301.         ((and containing-sexp
  302.           (/= (char-after containing-sexp) ?{))
  303.          ;; line is expression, not statement:
  304.          ;; indent to just after the surrounding open.
  305.          (goto-char (1+ containing-sexp))
  306.          (current-column))
  307.         (t
  308.           ;; Statement level.  Is it a continuation or a new statement?
  309.           ;; Find previous non-comment character.
  310.           (if toplevel
  311.           (progn (icon-backward-to-noncomment (point-min))
  312.              (if (icon-is-continuation-line)
  313.                  icon-continued-statement-offset 0))
  314.         (if (null containing-sexp)
  315.             (progn (beginning-of-icon-defun)
  316.                (setq containing-sexp (point))))
  317.         (goto-char indent-point)
  318.         (icon-backward-to-noncomment containing-sexp)
  319.         ;; Now we get the answer.
  320.         (if (icon-is-continuation-line)
  321.             ;; This line is continuation of preceding line's statement;
  322.             ;; indent  icon-continued-statement-offset  more than the
  323.             ;; first line of the statement.
  324.             (progn
  325.               (icon-backward-to-start-of-continued-exp containing-sexp)
  326.               (+ icon-continued-statement-offset (current-column)
  327.              (if (save-excursion (goto-char indent-point)
  328.                          (skip-chars-forward " \t")
  329.                          (eq (following-char) ?{))
  330.                  icon-continued-brace-offset 0)))
  331.           ;; This line starts a new statement.
  332.           ;; Position following last unclosed open.
  333.           (goto-char containing-sexp)
  334.           ;; Is line first statement after an open-brace?
  335.           (or
  336.             ;; If no, find that first statement and indent like it.
  337.             (save-excursion
  338.               (if (looking-at "procedure\\s ")
  339.               (forward-sexp 3)
  340.             (forward-char 1))
  341.               (while (progn (skip-chars-forward " \t\n")
  342.                     (looking-at "#"))
  343.             ;; Skip over comments following openbrace.
  344.             (forward-line 1))
  345.               ;; The first following code counts
  346.               ;; if it is before the line we want to indent.
  347.               (and (< (point) indent-point)
  348.                (current-column)))
  349.             ;; If no previous statement,
  350.             ;; indent it relative to line brace is on.
  351.             ;; For open brace in column zero, don't let statement
  352.             ;; start there too.  If icon-indent-level is zero,
  353.             ;; use icon-brace-offset + icon-continued-statement-offset instead.
  354.             ;; For open-braces not the first thing in a line,
  355.             ;; add in icon-brace-imaginary-offset.
  356.             (+ (if (and (bolp) (zerop icon-indent-level))
  357.                (+ icon-brace-offset icon-continued-statement-offset)
  358.              icon-indent-level)
  359.                ;; Move back over whitespace before the openbrace.
  360.                ;; If openbrace is not first nonwhite thing on the line,
  361.                ;; add the icon-brace-imaginary-offset.
  362.                (progn (skip-chars-backward " \t")
  363.                   (if (bolp) 0 icon-brace-imaginary-offset))
  364.                ;; here we are
  365.                (current-indentation))))))))))
  366.  
  367. (defun icon-is-continuation-line ()
  368.   (let* ((ch (preceding-char))
  369.      (ch-syntax (char-syntax ch)))
  370.     (if (eq ch-syntax ?w)
  371.     (assoc (buffer-substring
  372.          (progn (forward-word -1) (point))
  373.          (progn (forward-word 1) (point)))
  374.            '(("do") ("dynamic") ("else") ("initial") ("link")
  375.          ("local") ("of") ("static") ("then")))
  376.       (not (memq ch '(0 ?\; ?\} ?\{ ?\) ?\] ?\" ?\' ?\n))))))
  377.  
  378. (defun icon-backward-to-noncomment (lim)
  379.   (let (opoint stop)
  380.     (while (not stop)
  381.       (skip-chars-backward " \t\n\f" lim)
  382.       (setq opoint (point))
  383.       (beginning-of-line)
  384.       (if (and (search-forward "#" opoint 'move)
  385.            (< lim (point)))
  386.       (forward-char -1)
  387.     (setq stop t)))))
  388.  
  389. (defun icon-backward-to-start-of-continued-exp (lim)
  390.   (if (memq (preceding-char) '(?\) ?\]))
  391.       (forward-sexp -1))
  392.   (while (icon-is-continued-line)
  393.     (end-of-line 0))
  394.   (beginning-of-line)
  395.   (if (<= (point) lim)
  396.       (goto-char (1+ lim)))
  397.   (skip-chars-forward " \t"))
  398.  
  399. (defun icon-is-continued-line ()
  400.   (save-excursion
  401.     (end-of-line 0)
  402.     (icon-is-continuation-line)))
  403.  
  404. (defun icon-backward-to-start-of-if (&optional limit)
  405.   "Move to the start of the last ``unbalanced'' if."
  406.   (or limit (setq limit (save-excursion (beginning-of-icon-defun) (point))))
  407.   (let ((if-level 1)
  408.     (case-fold-search nil))
  409.     (while (not (zerop if-level))
  410.       (backward-sexp 1)
  411.       (cond ((looking-at "else\\b")
  412.          (setq if-level (1+ if-level)))
  413.         ((looking-at "if\\b")
  414.          (setq if-level (1- if-level)))
  415.         ((< (point) limit)
  416.          (setq if-level 0)
  417.          (goto-char limit))))))
  418.  
  419. (defun mark-icon-function ()
  420.   "Put mark at end of Icon function, point at beginning."
  421.   (interactive)
  422.   (push-mark (point))
  423.   (end-of-icon-defun)
  424.   (push-mark (point))
  425.   (beginning-of-line 0)
  426.   (beginning-of-icon-defun))
  427.  
  428. (defun beginning-of-icon-defun ()
  429.   "Go to the start of the enclosing procedure; return t if at top level."
  430.   (interactive)
  431.   (if (re-search-backward "^procedure\\s \\|^end[ \t\n]" (point-min) 'move)
  432.       (looking-at "e")
  433.     t))
  434.  
  435. (defun end-of-icon-defun ()
  436.   (interactive)
  437.   (if (not (bobp)) (forward-char -1))
  438.   (re-search-forward "\\(\\s \\|^\\)end\\(\\s \\|$\\)" (point-max) 'move)
  439.   (forward-word -1)
  440.   (forward-line 1))
  441.  
  442. (defun indent-icon-exp ()
  443.   "Indent each line of the Icon grouping following point."
  444.   (interactive)
  445.   (let ((indent-stack (list nil))
  446.     (contain-stack (list (point)))
  447.     (case-fold-search nil)
  448.     restart outer-loop-done inner-loop-done state ostate
  449.     this-indent last-sexp
  450.     at-else at-brace at-do
  451.     (opoint (point))
  452.     (next-depth 0))
  453.     (save-excursion
  454.       (forward-sexp 1))
  455.     (save-excursion
  456.       (setq outer-loop-done nil)
  457.       (while (and (not (eobp)) (not outer-loop-done))
  458.     (setq last-depth next-depth)
  459.     ;; Compute how depth changes over this line
  460.     ;; plus enough other lines to get to one that
  461.     ;; does not end inside a comment or string.
  462.     ;; Meanwhile, do appropriate indentation on comment lines.
  463.     (setq innerloop-done nil)
  464.     (while (and (not innerloop-done)
  465.             (not (and (eobp) (setq outer-loop-done t))))
  466.       (setq ostate state)
  467.       (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
  468.                       nil nil state))
  469.       (setq next-depth (car state))
  470.       (if (and (car (cdr (cdr state)))
  471.            (>= (car (cdr (cdr state))) 0))
  472.           (setq last-sexp (car (cdr (cdr state)))))
  473.       (if (or (nth 4 ostate))
  474.           (icon-indent-line))
  475.       (if (or (nth 3 state))
  476.           (forward-line 1)
  477.         (setq innerloop-done t)))
  478.     (if (<= next-depth 0)
  479.         (setq outer-loop-done t))
  480.     (if outer-loop-done
  481.         nil
  482.       (if (/= last-depth next-depth)
  483.           (setq last-sexp nil))
  484.       (while (> last-depth next-depth)
  485.         (setq indent-stack (cdr indent-stack)
  486.           contain-stack (cdr contain-stack)
  487.           last-depth (1- last-depth)))
  488.       (while (< last-depth next-depth)
  489.         (setq indent-stack (cons nil indent-stack)
  490.           contain-stack (cons nil contain-stack)
  491.           last-depth (1+ last-depth)))
  492.       (if (null (car contain-stack))
  493.           (setcar contain-stack (or (car (cdr state))
  494.                     (save-excursion (forward-sexp -1)
  495.                             (point)))))
  496.       (forward-line 1)
  497.       (skip-chars-forward " \t")
  498.       (if (eolp)
  499.           nil
  500.         (if (and (car indent-stack)
  501.              (>= (car indent-stack) 0))
  502.         ;; Line is on an existing nesting level.
  503.         ;; Lines inside parens are handled specially.
  504.         (if (/= (char-after (car contain-stack)) ?{)
  505.             (setq this-indent (car indent-stack))
  506.           ;; Line is at statement level.
  507.           ;; Is it a new statement?  Is it an else?
  508.           ;; Find last non-comment character before this line
  509.           (save-excursion
  510.             (setq at-else (looking-at "else\\W"))
  511.             (setq at-brace (= (following-char) ?{))
  512.             (icon-backward-to-noncomment opoint)
  513.             (if (icon-is-continuation-line)
  514.             ;; Preceding line did not end in comma or semi;
  515.             ;; indent this line  icon-continued-statement-offset
  516.             ;; more than previous.
  517.             (progn
  518.               (icon-backward-to-start-of-continued-exp (car contain-stack))
  519.               (setq this-indent
  520.                 (+ icon-continued-statement-offset (current-column)
  521.                    (if at-brace icon-continued-brace-offset 0))))
  522.               ;; Preceding line ended in comma or semi;
  523.               ;; use the standard indent for this level.
  524.               (if at-else
  525.               (progn (icon-backward-to-start-of-if opoint)
  526.                  (setq this-indent (current-indentation)))
  527.             (setq this-indent (car indent-stack))))))
  528.           ;; Just started a new nesting level.
  529.           ;; Compute the standard indent for this level.
  530.           (let ((val (calculate-icon-indent
  531.                (if (car indent-stack)
  532.                    (- (car indent-stack))))))
  533.         (setcar indent-stack
  534.             (setq this-indent val))))
  535.         ;; Adjust line indentation according to its contents
  536.         (if (or (= (following-char) ?})
  537.             (looking-at "end\\b"))
  538.         (setq this-indent (- this-indent icon-indent-level)))
  539.         (if (= (following-char) ?{)
  540.         (setq this-indent (+ this-indent icon-brace-offset)))
  541.         ;; Put chosen indentation into effect.
  542.         (or (= (current-column) this-indent)
  543.         (progn
  544.           (delete-region (point) (progn (beginning-of-line) (point)))
  545.           (indent-to this-indent)))
  546.         ;; Indent any comment following the text.
  547.         (or (looking-at comment-start-skip)
  548.         (if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
  549.             (progn (indent-for-comment) (beginning-of-line))))))))))
  550.  
  551.