home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / contrib / emacs / el_old.txt < prev    next >
Internet Message Format  |  1995-02-03  |  21KB

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