PageRenderTime 91ms CodeModel.GetById 12ms app.highlight 65ms RepoModel.GetById 1ms app.codeStats 1ms

/work/eiffel.el

http://github.com/tybor/Liberty
Emacs Lisp | 2776 lines | 2096 code | 310 blank | 370 comment | 78 complexity | f93f00beb9e185edba6515dd772b3527 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1;;; eiffel.el --- major mode for editing Eiffel files.
   2
   3;; Copyright (C) 1989, 1990, 93, 94, 95, 96, 99, 2000, 01, 02, 03
   4;;                         Tower Technology Corporation,
   5;;                         Free Software Foundation,
   6;;                         Bob Weiner,
   7;;                         C. Adrian
   8
   9;; Authors: 1989-1990 Stephen Omohundro, ISE and Bob Weiner
  10;;          1993-1996 Tower Technology Corporation
  11;;          1999-2003 Martin Schwenke <martin@meltin.net>
  12;; Maintainer: martin@meltin.net
  13;; Keywords: eiffel languages oop
  14;; Requires: font-lock, compile, easymenu, imenu
  15
  16;; This file is derived from eiffel4.el from Tower Technology Corporation.
  17;;
  18;; Known bugs:
  19;;
  20;; * eif-short buffer doesn't get font locked under GNU Emacs 19.34.
  21;;
  22;; * eif-debug can hang under (at least) XEmacs 21.4.[89] in the wait
  23;;   loop if there is input pending (that is, if the user hits return
  24;;   an extra time).  Not yet tested under XEmacs 21.5.
  25;;
  26;; This file is distributed under the same terms as GNU Emacs.
  27
  28;; GNU Emacs is free software; you can redistribute it and/or modify
  29;; it under the terms of the GNU General Public License as published by
  30;; the Free Software Foundation; either version 2, or (at your option)
  31;; any later version.
  32
  33;; GNU Emacs is distributed in the hope that it will be useful,
  34;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  35;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36;; GNU General Public License for more details.
  37
  38;; You should have received a copy of the GNU General Public License
  39;; along with GNU Emacs; see the file COPYING.  If not, write to the
  40;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  41;; Boston, MA  02110-1301, USA
  42
  43;;; Commentary:
  44
  45;;  NEW VERSIONS
  46;;    The latest version of this mode is always available via:
  47;;      http://meltin.net/hacks/emacs/
  48
  49;;  INSTALLATION
  50;;    To install, simply copy this file into a directory in your
  51;;    load-path and add the following two commands in your .emacs file:
  52;;
  53;;    (add-to-list 'auto-mode-alist '("\\.e\\'" . eiffel-mode))
  54;;    (autoload 'eiffel-mode "eiffel" "Major mode for Eiffel programs" t)
  55;;
  56;;    Note: to be sure to have always a fresh eiffel.el, you can add the
  57;;    "SmartEiffel/misc" directory in the emacs load-path by adding:
  58;;
  59;;    (setq load-path (cons ".../SmartEiffel/misc" load-path))
  60
  61;;; History:
  62;;
  63
  64;; Add history stuff here!!!
  65
  66;;; Code:
  67
  68(require 'font-lock)
  69(require 'compile)
  70(require 'easymenu)
  71(require 'imenu)
  72
  73(defconst eiffel-version-string
  74  "$Id: eiffel.el,v 2.67 2003/06/14 10:41:01 martins Exp $"
  75  "Version string to make reporting bugs more meaningful.
  76Note that if this file becomes part of GNU Emacs then the file might
  77be changed by the Emacs maintainers without this version number
  78changing.  This means that if you are reporting a bug for a version
  79that was shipped with Emacs, you should report the Emacs version!")
  80
  81(defgroup eiffel nil
  82  "Eiffel mode for Emacs"
  83  :group 'oop)
  84
  85(defgroup eiffel-indent nil
  86  "Indentation variables in Eiffel mode"
  87  :prefix "eif-"
  88  :group 'eiffel)
  89
  90(defgroup eiffel-compile nil
  91  "Compilation support variables in Eiffel mode"
  92  :prefix "eif-"
  93  :group 'eiffel)
  94
  95(defun eif-customize ()
  96  "Run \\[customize-group] for the `eiffel' group."
  97  (interactive)
  98  (customize-group 'eiffel))
  99
 100;; Indentation amount variables.
 101;;
 102;; The default values correspond to style used in ``Eiffel: The
 103;; Language''.
 104
 105(defcustom eif-indent-increment 3
 106  "*Default indentation interval (in spaces)."
 107  :type 'integer
 108  :group 'eiffel-indent)
 109
 110(defcustom eif-class-level-kw-indent 0
 111  "*Indentation for Class level keywords.
 112Specified as number of `eif-indent-increments'.  See the variable
 113`eif-class-level-keywords-regexp'."
 114  :type 'integer
 115  :group 'eiffel-indent)
 116
 117(defcustom eif-extra-class-level-kw-indent 0
 118  "*Number of extra spaces to add to `eif-class-level-kw-indent'.
 119This results in the actual indentation of a class level keyword.  Can
 120be negative."
 121  :type 'integer
 122  :group 'eiffel-indent)
 123
 124(defcustom eif-class-level-comment-indent 0
 125  "*Indentation of comments at the beginning of a class.
 126Specified as number of `eif-indent-increments'."
 127  :type 'integer
 128  :group 'eiffel-indent)
 129
 130(defcustom eif-extra-class-level-comment-indent 0
 131  "*Number of spaces to add to `eif-class-level-comment-indent'.
 132This results in the actual indentation of a class level comment.  Can
 133be negative."
 134  :type 'integer
 135  :group 'eiffel-indent)
 136
 137(defcustom eif-inherit-level-kw-indent 2
 138  "*Indentation of keywords falling under the Inherit clause.
 139Specified as number of `eif-indent-increments'.  See the variable
 140`eif-inherit-level-keywords'."
 141  :type 'integer
 142  :group 'eiffel-indent)
 143
 144(defcustom eif-extra-inherit-level-kw-indent 0
 145  "*Number of spaces to add to `eif-inherit-level-kw-indent'.
 146This results in the actual indentation of an inherit level keyword.
 147Can be negative."
 148  :type 'integer
 149  :group 'eiffel-indent)
 150
 151(defcustom eif-feature-level-indent 1
 152  "*Indentation amount of features.
 153Specified as number of `eif-indent-increments'."
 154  :type 'integer
 155  :group 'eiffel-indent)
 156
 157(defcustom eif-extra-feature-level-indent 0
 158  "*Number of spaces to add to `eif-feature-level-indent'.
 159This results in the indentation of a feature.  Can be negative."
 160  :type 'integer
 161  :group 'eiffel-indent)
 162
 163(defcustom eif-feature-level-kw-indent 2
 164  "*Indentation of keywords belonging to individual features.
 165Specified as number of `eif-indent-increments'.  See the variable
 166`eif-feature-level-keywords-regexp'."
 167  :type 'integer
 168  :group 'eiffel-indent)
 169
 170(defcustom eif-extra-feature-level-kw-indent 0
 171  "*Number of spaces to add to `eif-feature-level-kw-indent'.
 172This results in the actual indentation of a feature level keyword.
 173Can be negative."
 174  :type 'integer
 175  :group 'eiffel-indent)
 176
 177(defcustom eif-feature-level-comment-indent 3
 178  "*Indentation of comments at the beginning of a feature.
 179Specified as number of `eif-indent-increments'."
 180  :type 'integer
 181  :group 'eiffel-indent)
 182
 183(defcustom eif-extra-feature-level-comment-indent 0
 184  "*Number of spaces to add to `eif-feature-level-comment-indent'.
 185This results in the actual indentation of a feature level comment.
 186Can be negative."
 187  :type 'integer
 188  :group 'eiffel-indent)
 189
 190(defcustom eif-body-comment-indent 0
 191  "*Indentation of comments in the body of a routine.
 192Specified as number of `eif-indent-increments')"
 193  :type 'integer
 194  :group 'eiffel-indent)
 195
 196(defcustom eif-extra-body-comment-indent 0
 197  "*Number of spaces to add to `eif-body-comment-indent'.
 198This results in the actual indentation of a routine body comment.  Can
 199be negative."
 200  :type 'integer
 201  :group 'eiffel-indent)
 202
 203(defcustom eif-check-keyword-indent 0
 204  "*Extra indentation for the check clause as described in ETL.
 205Specified as number of `eif-indent-increments'.  Default is 0, which
 206is different than in ETL's 1."
 207  :type 'integer
 208  :group 'eiffel-indent)
 209
 210(defcustom eif-extra-check-keyword-indent 0
 211  "*Number of spaces to add to `eif-check-keyword-indent'.
 212This results in the actual indentation of a check keyword.  Can be
 213negative."
 214  :type 'integer
 215  :group 'eiffel-indent)
 216
 217(defcustom eif-rescue-keyword-indent -1
 218  "*Extra indentation for the rescue clause as described in ETL.
 219Specified as number of `eif-indent-increments'.  Default is -1."
 220  :type 'integer
 221  :group 'eiffel-indent)
 222
 223(defcustom eif-extra-rescue-keyword-indent 0
 224  "*Number of spaces to add to `eif-rescue-keyword-indent'.
 225This results in the actual indentation of a rescue keyword.  Can be
 226negative."
 227  :type 'integer
 228  :group 'eiffel-indent)
 229
 230(defcustom eif-then-indent 0
 231  "*Indentation for a `then' appearing on a line by itself.
 232This is as opposed to a `then' on the same line as an `if'.  Specified
 233as number of `eif-indent-increments'."
 234  :type 'integer
 235  :group 'eiffel-indent)
 236
 237(defcustom eif-extra-then-indent 0
 238  "*Number of spaces to add to `eif-then-indent'.
 239This results in the actual indentation of a `then' appearing on a line
 240by itself.  Can be negative."
 241  :type 'integer
 242  :group 'eiffel-indent)
 243
 244(defcustom eif-continuation-indent 1
 245  "*Extra indentation for a continued statement line.
 246Specified as number of `eif-indent-increments'."
 247  :type 'integer
 248  :group 'eiffel-indent)
 249
 250(defcustom eif-extra-continuation-indent 0
 251  "*Number of spaces to add to `eif-continuation-indent'.
 252This results in the actual indentation of a continued statement
 253line.  Can be negative."
 254  :type 'integer
 255  :group 'eiffel-indent)
 256
 257(defcustom eif-string-continuation-indent 0
 258  "*Extra indentation for a continued string.
 259Specified as number of `eif-indent-increments'."
 260  :type 'integer
 261  :group 'eiffel-indent)
 262
 263(defcustom eif-extra-string-continuation-indent -1
 264  "*Number of spaces to add to `eif-string-continuation-indent'.
 265This results in the actual indentation of a continued string.  Can be
 266negative."
 267  :type 'integer
 268  :group 'eiffel-indent)
 269
 270(defcustom eif-indent-string-continuations-relatively-flag t
 271  "*Non-nil means string continuations are indented relative to 1st character.
 272That is, `eif-string-continuation-indent' and
 273`eif-extra-string-continuation-indent' are added to position of first
 274character of string.  If nil, string continuations are indented
 275relative to indent of previous line."
 276  :type 'boolean
 277  :group 'eiffel-indent)
 278
 279(defcustom eif-set-tab-width-flag t
 280  "*Non-nil means `tab-width' is set to `eif-indent-increment' in `eiffel-mode'."
 281  :type 'boolean
 282  :group 'eiffel-indent)
 283
 284(defcustom eif-preprocessor-indent 0
 285  "*Indentation for lines GOBO preprocessor directives.
 286Specified as number of `eif-indent-increments' from left margin."
 287  :type 'integer
 288  :group 'eiffel-indent)
 289
 290(defcustom eif-fill-max-save 4096
 291  "*Maximum size of a paragraph to save before filling.
 292Normally \\[eif-fill-paragraph] will mark a buffer as modified even if
 293the fill operation does not make any changes.  If the paragraph being
 294filled is smaller than the value of this variable then the contents of
 295the paragraph will be saved for comparison with the paragraph after
 296the fill operation.  If they are the same, the buffer modification
 297state is restored.  Set this to 0 to disable this feature, or a very
 298big number to enable it for all paragraphs."
 299  :type 'integer
 300  :group 'eiffel-indent)
 301
 302(defcustom eif-use-gnu-eiffel t
 303  "*If t include support for compilation using GNU Liberty Eiffel."
 304  :type 'boolean
 305  :group 'eiffel-compile)
 306
 307(defcustom eif-se-command
 308  "se"
 309  "*Program to use for compiling Eiffel programs.
 310The default is \"se\"."
 311  :type 'string
 312  :group 'eiffel-compile)
 313
 314(defcustom eif-compile-options ""
 315  "*Options to use for compiling Eiffel programs."
 316  :type 'string
 317  :group 'eiffel-compile)
 318
 319;;
 320;; No user-customizable definitions below this point.
 321;;
 322
 323;;
 324;; Indentation macros.
 325;;
 326
 327(defmacro eif-class-level-kw-indent-m ()
 328  "Indentation amount for Class level keywords (in number of spaces)."
 329  '(+ (* eif-class-level-kw-indent eif-indent-increment)
 330      eif-extra-class-level-kw-indent))
 331
 332(defmacro eif-class-level-comment-indent-m ()
 333  "Indentation amount for Class level comments (in number of spaces)."
 334  '(+ (* eif-class-level-comment-indent eif-indent-increment)
 335      eif-extra-class-level-comment-indent))
 336
 337(defmacro eif-inherit-level-kw-indent-m ()
 338  "Indentation amount for Inherit level keywords (in number of spaces)."
 339  '(+ (* eif-inherit-level-kw-indent eif-indent-increment)
 340      eif-extra-inherit-level-kw-indent))
 341
 342(defmacro eif-feature-level-indent-m ()
 343  "Indentation amount for features (in number of spaces)."
 344  '(+ (* eif-feature-level-indent eif-indent-increment)
 345      eif-extra-feature-level-indent))
 346
 347(defmacro eif-feature-level-kw-indent-m ()
 348  "Indentation amount for Feature level keywords (in number of spaces)."
 349  '(+ (* eif-feature-level-kw-indent eif-indent-increment)
 350      eif-extra-feature-level-kw-indent))
 351
 352(defmacro eif-body-comment-indent-m ()
 353  "Indentation amount for comments in routine bodies (in number of spaces)."
 354  '(+ (* eif-body-comment-indent eif-indent-increment)
 355      eif-extra-body-comment-indent))
 356
 357(defmacro eif-feature-level-comment-indent-m ()
 358  "Indentation amount for Feature level comments (in number of spaces)."
 359  '(+ (* eif-feature-level-comment-indent eif-indent-increment)
 360      eif-extra-feature-level-comment-indent))
 361
 362(defmacro eif-check-keyword-indent-m ()
 363  "Indentation amount for Check keyword (in number of spaces)."
 364  '(+ (* eif-check-keyword-indent eif-indent-increment)
 365      eif-extra-check-keyword-indent))
 366
 367(defmacro eif-rescue-keyword-indent-m ()
 368  "Indentation amount for Rescue keyword (in number of spaces)."
 369  '(+ (* eif-rescue-keyword-indent eif-indent-increment)
 370      eif-extra-rescue-keyword-indent))
 371
 372(defmacro eif-then-indent-m ()
 373  "Indentation amount for `then' appearing on a line by itself (in number of spaces)."
 374  '(+ (* eif-then-indent eif-indent-increment)
 375      eif-extra-then-indent))
 376
 377(defmacro eif-continuation-indent-m ()
 378  "Indentation amount for a statement continuation line (in number of spaces)."
 379  '(+ (* eif-continuation-indent eif-indent-increment)
 380      eif-extra-continuation-indent))
 381
 382(defmacro eif-string-continuation-indent-m ()
 383  "Indentation amount for a statement continuation line (in number of spaces)."
 384  '(+ (* eif-string-continuation-indent eif-indent-increment)
 385      eif-extra-string-continuation-indent))
 386
 387(defmacro eif-preprocessor-indent-m ()
 388  "Indentation amount for a preprocessor statement (in number of spaces)."
 389  '(* eif-preprocessor-indent eif-indent-increment))
 390
 391;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 392;;          Keyword Regular Expression Constants.               ;;
 393;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 394
 395(defconst eif-non-id-char-regexp "\\S_" ;; "[^a-z0-9_]"
 396  "The characters that are not part of identifiers.")
 397
 398(defun eif-post-anchor (regexp)
 399  "Anchor given REGEXP with end-word delimiter and `eif-non-id-char-regexp'."
 400  (concat "\\(" regexp "\\)\\>" eif-non-id-char-regexp))
 401
 402(defun eif-word-anchor (regexp)
 403  "Anchor given REGEXP with word delimiters and `eif-non-id-char-regexp'."
 404  (concat "\\<\\(" regexp "\\)\\>" eif-non-id-char-regexp))
 405
 406(defun eif-anchor (regexp)
 407  "Anchor given REGEXP front and back to match line break or non-symbol char."
 408  (concat "\\(^\\|\\S_\\<\\)\\(" regexp "\\)\\($\\|\\>\\S_\\)"))
 409
 410;; Note invariant is handled as a special case since it is both a
 411;; class-level and a from-level keyword
 412;; Note obsolete is handled as a special case since it is both a
 413;; class-level and a feature-level keyword
 414;; Note create, note, and indexing are also handled as special cases
 415(defconst eif-class-level-keywords
 416  (concat
 417   "\\(?:"
 418   (regexp-opt '("deferred" "expanded" "reference" "separate"))
 419   "[ \t]+\\)?class"
 420   "\\|"
 421   (regexp-opt '("inherit" "insert" "convert" "creation" "feature")))
 422  "Keywords introducing class-level clauses.
 423Note that `invariant', `obsolete', `indexing', `note', and `create' are not included here since can
 424function as more than one type of keyword.")
 425
 426(defconst eif-class-level-keywords-regexp
 427  (eif-word-anchor eif-class-level-keywords)
 428  "Regexp of keywords introducing class level clauses, with some context.
 429See `eif-class-level-keywords'.")
 430
 431(defconst eif-inherit-level-keywords
 432  (regexp-opt '("rename" "redefine" "undefine" "select" "export"))
 433  "Those keywords which introduce subclauses of the inherit clause.")
 434
 435(defconst eif-feature-level-keywords
 436  (regexp-opt '("require" "local" "deferred" "separate" "do" "once" "ensure" "alias" "external" "attribute"))
 437  "Those keywords which are internal to features (in particular, routines).")
 438
 439(defconst eif-feature-level-keywords-regexp
 440  (eif-word-anchor eif-feature-level-keywords)
 441  "Regexp of keywords internal to features (usually routines).
 442See `eif-feature-level-keywords'.")
 443
 444(defconst eif-end-keyword "end" "The `end' keyword.")
 445
 446(defconst eif-end-on-current-line ".*[ \t]end[ \t]*;?[ \t]*\\(--.*\\)?$"
 447  "Regular expression to identify lines ending with the `end' keyword.")
 448
 449(defconst eif-control-flow-keywords
 450  (regexp-opt '("if" "inspect" "from" "debug"))
 451  "Keywords which introduce control-flow constructs.")
 452
 453(defconst eif-control-flow-matching-keywords
 454  (concat (regexp-opt '("deferred" "do" "once")) "\\|" eif-control-flow-keywords)
 455  "Keywords that may cause the indentation of an `eif-control-flow-keyword'.
 456If these occur prior to an `eif-control-flow-keyword' then the
 457`eif-control-flow-keyword' is indented.  Note that technically, `end'
 458is part of this list but it is handled separately in the function
 459\[eif-matching-kw\].")
 460
 461(defconst eif-control-flow-matching-keywords-regexp
 462  (eif-word-anchor eif-control-flow-matching-keywords)
 463  "Regexp of keywords maybe causing indentation of `eif-control-flow-keyword'.
 464See `eif-control-flow-keywords'.")
 465
 466(defconst eif-check-keyword "check"
 467  "The `check' keyword.")
 468
 469(defconst eif-check-keywords-regexp
 470  (eif-word-anchor eif-check-keyword)
 471  "The `check' keyword (with trailing context).")
 472
 473;; FIXME: Doesn't work if once keyword is followed by a string on next
 474;; line, but didn't get broken by this attempt at factoring.
 475(defconst eif-check-matching-keywords-regexp
 476  eif-control-flow-matching-keywords-regexp
 477  "Keywords that may cause the indentation of an `eif-check-keyword'.
 478If these occur prior to an `eif-check-keyword' then the
 479`eif-check-keyword' is indented.  Note that technically, `end' is part
 480of this list but it is handled separately in the function
 481\[eif-matching-kw\].  See also `eif-control-flow-matching-keywords-regexp'.")
 482
 483;; FIXME: This could be fixed or removed.
 484(defconst eif-end-keyword-regexp "\\<end\\>"
 485  "The `end' keyword with context.")
 486
 487(defconst eif-end-matching-keywords
 488  (concat (regexp-opt '("attribute" "check" "class" "feature" "rename" "redefine" "undefine"
 489          "select" "export" "separate" "external" "alias")) "\\|"
 490          eif-control-flow-matching-keywords)
 491  "Those keywords whose clause is terminated by an `end' keyword.")
 492
 493(defconst eif-end-matching-keywords-regexp
 494  (eif-word-anchor eif-end-matching-keywords)
 495  "Regexp of keywords whose clause is terminated by an `end' keyword.
 496See `eif-end-matching-keywords'.")
 497
 498(defconst eif-rescue-keyword "rescue"  "The `rescue' keyword.")
 499
 500(defconst eif-obsolete-keyword "obsolete"  "The `obsolete' keyword.")
 501
 502(defconst eif-indexing-keyword
 503  (regexp-opt '("note" "indexing"))
 504  "The `indexing' and `note' keywords.")
 505
 506(defconst eif-indexing-keyword-regexp
 507  (eif-post-anchor eif-indexing-keyword)
 508  "Regexp matching `indexing' and `note' keywords, with trailing context.")
 509
 510(defconst eif-rescue-keywords-regexp
 511  (eif-word-anchor eif-rescue-keyword)
 512  "The `rescue' keyword (with trailing context).")
 513
 514(defconst eif-rescue-matching-keywords-regexp
 515  (eif-word-anchor (regexp-opt '("deferred" "do" "once")))
 516  "Keywords that may cause the indentation of an `eif-rescue-keyword'.
 517If these occur prior to an `eif-rescue-keyword' then the
 518`eif-rescue-keyword' is indented.  Note that technically, `end' is
 519part of this list but it is handled separately in the function
 520\[eif-matching-kw\].  See also `eif-control-flow-matching-keywords-regexp'.")
 521
 522(defconst eif-from-level-keywords
 523  (regexp-opt '("until" "variant" "loop"))
 524  "Keywords occuring inside of a from clause.")
 525
 526(defconst eif-from-level-keywords-regexp
 527  (eif-word-anchor eif-from-level-keywords)
 528  "Regexp of keywords occuring inside of a from clause.
 529See `eif-from-level-keywords'.")
 530
 531(defconst eif-from-keyword  "from" "The keyword `from'.")
 532
 533(defconst eif-if-or-inspect-level-keywords
 534  (regexp-opt '("elseif" "else" "when"))
 535  "Keywords occuring inside of an if or inspect clause.")
 536
 537(defconst eif-if-or-inspect-level-keywords-regexp
 538  (eif-word-anchor eif-if-or-inspect-level-keywords)
 539  "Regexp of keywords occuring inside of an if or inspect clause.
 540See eif-if-or-inspect-level-keywords.")
 541
 542(defconst eif-if-or-inspect-keyword-regexp
 543  (eif-word-anchor (regexp-opt '("if" "inspect")))
 544  "Regexp matching the `if' or `inspect' keywords.")
 545
 546(defconst eif-then-keyword ".*[ \t)]then[ \t]*$"
 547  "The keyword `then' with possible leading text.")
 548
 549(defconst eif-solitary-then-keyword "then" "The keyword `then'.")
 550
 551(defconst eif-then-matching-keywords
 552  (regexp-opt '("if" "elseif" "when") t)
 553  "Keywords that may alter the indentation of an `eif-then-keyword'.
 554If one of these occur prior to an `eif-then-keyword' then this sets
 555the indentation of the `eif-then-keyword'.  Note that technically,
 556`end' is part of this list but it is handled separately in the
 557function \[eif-matching-kw\].  See also
 558`eif-control-flow-matching-keywords-regexp'.")
 559
 560(defconst eif-invariant-keyword "invariant" "The `invariant' keyword.")
 561
 562(defconst eif-invariant-matching-keywords
 563  (regexp-opt '("from" "feature"))
 564  "Keywords that may cause the indentation of an `eif-invarient-keyword'.
 565If one of these occurs prior to an `eif-invariant-keyword' then the
 566`eif-invariant-keyword' is indented.  Note that technically, `end' is
 567part of this list but it is handled separately in the function
 568\[eif-matching-kw\].  See also `eif-control-flow-matching-keywords-regexp'.")
 569
 570(defconst eif-obsolete-matching-keywords
 571  (regexp-opt '("is" "class") t)
 572  "Keywords that may cause the indentation of an `eif-obsolete-keyword'.
 573If one of these occurs prior to an `eif-obsolete-keyword' then the
 574`eif-obsolete-keyword' is indented.")
 575
 576(defconst eif-create-keyword
 577  "create"
 578  "Eiffel create keyword.  Can be used at class or minor level.")
 579
 580(defconst eif-create-keyword-regexp
 581  (eif-post-anchor eif-create-keyword)
 582  "Regexp matching `create' keyword, with trailing context.")
 583
 584(defconst eif-indentation-keywords
 585  (concat (regexp-opt '("note" "indexing" "rescue" "inherit" "insert" "convert" "create" "creation"
 586          "invariant" "require" "local" "ensure" "obsolete")) "\\|"
 587          eif-from-level-keywords "\\|"
 588          eif-if-or-inspect-level-keywords "\\|"
 589          eif-end-matching-keywords)
 590  "Keywords that match any eiffel keyword triggering indentation.")
 591
 592(defconst eif-indentation-keywords-regexp
 593  (eif-word-anchor eif-indentation-keywords)
 594  "Regexp of keywords that match any eiffel keyword triggering indentation.
 595See `eif-indentation-keywords'.")
 596
 597(defconst eif-once-non-indent-regexp
 598  "\\s-*once\\(\\s-\\|\n\\)+\""
 599  "Regexp of Eiffel once keyword in context not affecting indentation.")
 600
 601(defconst eif-feature-indentation-keywords-regexp
 602  (eif-word-anchor (regexp-opt '("convert" "creation" "feature")))
 603  "Keywords which denote the presence of features following them.")
 604
 605(defconst eif-is-keyword-regexp "\\(.*[ \t)]\\)?is[ \t]*\\(--.*\\)?$"
 606  "The `is' keyword (with some context).")
 607
 608(defconst eif-multiline-routine-is-keyword-regexp
 609  ".*([^)]*)\\([ \t\n]*\\|[ \t\n]*:[][ \t\nA-Za-x0-9_,]*\\)is[ \t]*\\(--.*\\)?$"
 610  "The `is' keyword (with some context).")
 611
 612(defconst eif-operator-keywords
 613  (regexp-opt '("and" "or" "implies"))
 614  "Eiffel operator keywords.")
 615
 616(defconst eif-operator-regexp
 617  (concat "[ \t]*\\([@*/+]\\|-[^-]\\|\\<\\("
 618          eif-operator-keywords
 619          "\\)[ \t(]\\)")
 620  "Eiffel operators - used to identify continuation lines.
 621See `eif-operator-keywords'.")
 622
 623(defconst eif-operator-eol-regexp
 624  (concat ".*\\([@*/+-]\\|\\<\\(" eif-operator-keywords
 625          "\\)\\|:=\\)[ \t]*\\(--.*\\)?$")
 626  "Eiffel operators - used to identify continuation lines.")
 627
 628(defconst eif-all-keywords
 629  (concat eif-indentation-keywords    "\\|"
 630          eif-solitary-then-keyword   "\\|"
 631          eif-create-keyword          "\\|"
 632          eif-end-keyword)
 633  "Regexp matching (nearly) any eiffel keyword in a line.
 634Does not include `is'.")
 635
 636(defconst eif-all-keywords-regexp
 637  (concat "\\("
 638          (eif-word-anchor eif-all-keywords) "\\)")
 639  "Anchored regexp matching (nearly) any eiffel keyword in a line.
 640Does not include `is'.  See `eif-all-keywords'.")
 641
 642(defconst eiffel-comment-start-skip
 643  "--+|?[ \t]*"
 644  "Regexp matching the beginning of an Eiffel comment.")
 645
 646(defconst eif-non-source-line
 647  (concat "[ \t]*\\(\\(" "--" "\\).*\\)?$")
 648  "RE matching line with only whitespace and comment or preprocessor keyword.")
 649
 650(defconst eif-variable-or-const-regexp "[^()\n]*:[^=].*"
 651  "RE to match a variable or constant declaration.")
 652
 653;; Factor out some important important regexps for use in
 654;; eif-{beginning,end}-of-feature.
 655
 656(defun eiffel-feature-re ()
 657  "Liberty Eiffel feature declarations"
 658  (let* ((argument-name "\\(?:[A-Za-z]*[a-z0-9_]+[A-Za-z0-9_]*\\)")
 659         (feature-name (concat "\\(?:\\(infix\\|prefix\\)\\s-+\".+?\"\\|" argument-name "\\(?:\\s-+alias\\s-+\".+?\"\\)?\\)"))
 660         (type-name "\\(?:like\\s-+\\sw+\\|[A-Z]\\sw*\\(?:\\[.+?\\]\\)?\\)"))
 661    (concat
 662     "\\(?:"
 663     "\\(?:\\<frozen\\s-\\)?"
 664     "\\s-*" feature-name "\\s-*,?"
 665     "\\)+"
 666     "\\(?:(" ; no \\s-* because it is matched above, if there is no trailing coma
 667     "\\(?:"
 668     "\\(?:\\s-*" argument-name "\\s-*,?\\)+?"
 669     ":" type-name "\\s-*;?"
 670     "\\)*?"
 671     ")\\)?" ; no \\s-* because it is matched above, if there is no trailing semi-colon
 672     "\\(?:\\s-*:\\s-*" type-name "\\)?"
 673     "\\(?:\\s-*assign\\s-*\\sw+\\)?"
 674     "\\(?:\\s-*is\\>\\)?")))
 675
 676(defconst eif-routine-begin-regexp
 677  ;"\\([a-z][a-zA-Z_0-9]*\\)\\s-*\\(([^)]*)\\)?\\s-*\\(:\\s-*[A-Z][A-Z0-9_]*\\(\\s-*\\[[^\\]]*\\]\\)?\\)?\\s-*\\(assign\\s-*[a-zA-Z0-9_]+\\)?\\s-*\\<is\\>\\s-*\\(--.*\\)?$"
 678 (eiffel-feature-re)
 679  "Regexp matching the beginning of an Eiffel routine declaration.")
 680
 681(message (concat "Liberty Eiffel features: " eif-routine-begin-regexp))
 682
 683(defconst eif-attribute-regexp
 684  (concat "[a-z_][^-:\n]*:\\s-*"
 685          "\\(like\\s-*[a-zA-Z][a-z_0-9]*\\|"
 686          "\\(\\(expanded\\|reference\\)\\s-*\\)?[A-Z][A-Z_0-9]*"
 687          "\\(\\s-*\\[[^-\n]*\\]\\)?\\)"
 688          "\\s-*\\($\\|[;)].*\\|--.*\\)")
 689  "Regexp matching an Eiffel attribute, parameter or local variable.")
 690
 691(defconst eif-constant-regexp
 692  "[a-z_][^-:\n]*:[^-\n]*\\<is\\>\\s-*[^ \t\n]"
 693  "Regexp matching an Eiffel constant declaration.")
 694
 695(defconst eif-probably-feature-regexp
 696  (concat "\\(" eif-routine-begin-regexp
 697          "\\|" eif-attribute-regexp
 698          "\\|" eif-constant-regexp "\\)")
 699  "Regexp probably matching an Eiffel feature.
 700This will also match local variable and parameter declarations.")
 701
 702;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 703
 704(defvar eif-matching-indent -1
 705  "Indentation of the keyword found on the last call to \[eif-matching-kw\].
 706-1 if no match was found.")
 707
 708(defvar eif-matching-kw-for-end nil)
 709
 710;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 711
 712;;
 713;; Font-lock support.
 714;;
 715;; Rewritten from scratch by Cyril Adrian <cyril.adrian@gmail.com>
 716;; Specific to Liberty Eiffel
 717;;
 718
 719(defconst eiffel-keywords-feature
 720  '("agent" "all" "and" "as" "assign" "attribute" "check" "class"
 721    "convert" "create" "debug" "deferred" "do" "else" "elseif" "end" "ensure"
 722    "expanded" "export" "external" "feature" "from" "if" "implies"
 723    "indexing" "inherit" "insert" "inspect" "invariant" "is" "like"
 724    "local" "loop" "not" "note" "obsolete" "old" "once" "only" "or"
 725    "redefine" "rename" "require" "rescue" "retry" "select" "separate" "then"
 726    "undefine" "until" "variant" "when" "xor"))
 727
 728(defconst eiffel-keywords
 729  '("agent" "alias" "all" "and" "as" "assign" "attribute" "check" "class"
 730    "convert" "create" "debug" "deferred" "do" "else" "elseif" "end" "ensure"
 731    "expanded" "export" "external" "feature" "from" "frozen" "if" "implies"
 732    "indexing" "infix" "inherit" "insert" "inspect" "invariant" "is" "like"
 733    "local" "loop" "not" "note" "obsolete" "old" "once" "only" "or" "prefix"
 734    "redefine" "rename" "require" "rescue" "retry" "select" "separate" "then"
 735    "undefine" "until" "variant" "when" "xor"))
 736
 737(defconst eiffel-constants
 738  '("Current" "False" "Precursor" "Result" "True" "Void"))
 739
 740(defun eiffel-string-re ()
 741  "Liberty Eiffel strings"
 742  (concat "U?\"\\(?:"
 743          "\\(?:\\(?:[^%\"\n]\\|%[^\n]\\)*?\\)" ; single-line strings
 744          "\\|"
 745          "\\(?:\\(?:[^%\"\n]\\|%[^\n]\\)*?%[ \t]*\n\\(?:[ \t]*%\\(?:[^%\"\n]\\|%[^\n]\\)*?%[ \t]*\n\\)*[ \t]*%\\(?:[^%\"\n]\\|%[^\n]\\)*?\\)" ; older multiline strings
 746          "\\|"
 747          "\\(?:[[{][ \t]*\n\\(?:.*?\n\\)*?[ \t]*[]}]\"\\)" ; newer multiline strings
 748          "\\)\""))
 749
 750(defun eiffel-wordstart-re ()
 751  "start of words"
 752  "\\<\\(")
 753
 754(defun eiffel-wordend-re ()
 755  "end of words"
 756  (concat "\\)\\>"))
 757
 758(defun eiffel-keywords-re ()
 759  (concat
 760   (eiffel-wordstart-re)
 761   (regexp-opt eiffel-keywords)
 762   (eiffel-wordend-re)))
 763
 764(defun eiffel-constants-re ()
 765  (concat
 766   (eiffel-wordstart-re)
 767   (regexp-opt eiffel-constants)
 768   (eiffel-wordend-re)))
 769
 770(defun eiffel-preprocessor-re ()
 771  (concat
 772   (eiffel-wordstart-re)
 773   (regexp-opt '("c_inline_c" "c_inline_h" "not_yet_implemented" "se_breakpoint" "breakpoint"  "to_pointer"
 774                 "is_expanded_type" "is_basic_expanded_type"
 775                 "object_size" "object_id_memory"
 776                 "se_guru01" "se_guru02" "se_guru03"))
 777   (eiffel-wordend-re)))
 778
 779(defvar eiffel-font-lock-defaults
 780  (append
 781   `(
 782     ("--|\\(.*\\)\n"               .    font-lock-comment-face)
 783     ("--\\(.*\\)\n"                .    font-lock-doc-face)
 784     (,(eiffel-string-re)           .    font-lock-string-face)
 785     ("'\\(?:[^'%]\\|%.\\)'"        .    font-lock-string-face)
 786     ("\\<\\([A-Z][A-Z0-9_]*\\)\\>" .    font-lock-type-face)
 787     (,(eiffel-keywords-re)            1 font-lock-keyword-face)
 788     (,(eiffel-constants-re)           1 font-lock-builtin-face)
 789     (,(eiffel-preprocessor-re)        1 font-lock-preprocessor-face)))
 790  "Default highlighting expressions for Liberty Eiffel mode")
 791
 792;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 793
 794;;
 795;; Compilation support for GNU SmartEiffel.
 796;;
 797
 798(defvar eif-compile-dir nil
 799  "Current directory where Eiffel compilations are taking place.
 800Possibly used for error location.")
 801
 802(defvar eif-root-class nil
 803  "Current Eiffel root class being compiled/debugged.")
 804
 805(defvar eif-compile-target nil
 806  "Current Eiffel compilation target.")
 807
 808(defvar eif-debug-target nil
 809  "Current Eiffel debug target.")
 810
 811(defvar eif-root-proc nil
 812  "Current Eiffel root procedure.")
 813
 814(defvar eif-run-command nil
 815  "Current command to run after Eiffel compile.")
 816
 817(defvar eif-debug-command nil
 818  "Current debug command to run after Eiffel debug compile.")
 819
 820(defun eif-compilation-mode-hook ()
 821  "Hook function to set local value for `compilation-error-screen-columns'.
 822This should be nil for SmartEiffel compiles, because column positions are
 823returned as character positions rather than screen columns."
 824  ;; In Emacs > 20.7 compilation-error-screen-columns is buffer local.
 825  (or (assq 'compilation-error-screen-columns (buffer-local-variables))
 826      (make-local-variable 'compilation-error-screen-columns))
 827  (setq compilation-error-screen-columns nil))
 828
 829(defun eif-compile ()
 830  "Compile an Eiffel root class."
 831  (interactive)
 832  (eif-compile-prompt)
 833  (eif-compile-internal))
 834
 835(defun eif-set-compile-options ()
 836  "Set Eiffel compiler options."
 837  (interactive)
 838  (setq eif-compile-options
 839        (read-string "Eiffel compiler options: " eif-compile-options)))
 840
 841;; Taken from Emacs 20.3 subr.el (just in case we're running under Emacs 19).
 842(defun eif-split-string (string &optional separators)
 843  "Split STRING into substrings separated by SEPARATORS.
 844Each match for SEPARATORS is a splitting point.  The substrings
 845between the splitting points are made into a list which is returned.
 846If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\".
 847
 848If there is match for SEPARATORS at the beginning of STRING, we do not
 849include a null substring for that.  Likewise, if there is a match
 850at the end of STRING, we do not include a null substring for that."
 851  (let ((rexp (or separators "[ \f\t\n\r\v]+"))
 852        (start 0)
 853        notfirst
 854        (list nil))
 855    (while (and (string-match rexp string
 856                              (if (and notfirst
 857                                       (= start (match-beginning 0))
 858                                       (< start (length string)))
 859                                  (1+ start) start))
 860                (< (match-beginning 0) (length string)))
 861      (setq notfirst t)
 862      (or (eq (match-beginning 0) 0)
 863          (and (eq (match-beginning 0) (match-end 0))
 864               (eq (match-beginning 0) start))
 865          (setq list
 866                (cons (substring string start (match-beginning 0))
 867                      list)))
 868      (setq start (match-end 0)))
 869    (or (eq start (length string))
 870        (setq list
 871              (cons (substring string start)
 872                    list)))
 873    (nreverse list)))
 874
 875(defun eif-run ()
 876  "Run a compiled Eiffel program."
 877  (interactive)
 878  (setq eif-run-command
 879        (read-string "Command to run: "
 880                     (or eif-run-command
 881                         eif-compile-target
 882                         (file-name-sans-extension
 883                          (if (or (eq system-type 'windows-nt) (eq system-type 'cygwin))
 884                              buffer-file-name
 885                            (file-name-nondirectory (buffer-file-name)))))))
 886  (eif-run-internal))
 887
 888(defun eif-debug ()
 889  "Run the SmartEiffel debugger."
 890  (interactive)
 891
 892  (eif-compile-prompt)
 893
 894  (setq eif-debug-target
 895        (file-name-sans-extension
 896         (read-string "Debug target name: "
 897                      (or eif-debug-target
 898                          (concat eif-compile-target "_debug")))))
 899
 900  (let* ((eif-compile-options (concat "-sedb " eif-compile-options))
 901         (eif-compile-target eif-debug-target)
 902         (buff (eif-compile-internal))
 903         (proc (get-buffer-process buff)))
 904
 905    ;; This works under GNU Emacs, but hangs under at least some
 906    ;; versions of XEmacs if there is input pending.
 907    (while (eq (process-status proc) 'run)
 908      (sit-for 1))
 909
 910    (if (= (process-exit-status proc) 0)
 911        (progn
 912          (setq eif-debug-command
 913                (read-string "Debugger command to run: "
 914                             (or eif-debug-command
 915                                 eif-debug-target
 916                                 (file-name-sans-extension
 917                                  (if (eq system-type 'windows-nt)
 918                                      buffer-file-name
 919                                    (file-name-nondirectory
 920                                     (buffer-file-name)))))))
 921          (let ((eif-run-command eif-debug-command))
 922            (eif-run-internal))))))
 923
 924(defun eif-compile-prompt ()
 925  "Prompt for information required to compile an Eiffel root class."
 926
 927  ;; Do the save first, since the user might still have their hand on
 928  ;; the mouse.
 929  (save-some-buffers (not compilation-ask-about-save) nil)
 930
 931  (setq eif-compile-dir (file-name-directory (buffer-file-name)))
 932  (setq eif-root-class
 933        (file-name-sans-extension
 934         (read-string "Name of root class: "
 935                      (or eif-compile-target
 936                          (file-name-sans-extension
 937                           (file-name-nondirectory (buffer-file-name)))))))
 938  (setq eif-compile-target eif-root-class)
 939  (setq eif-root-proc
 940        (read-string "Name of root procedure: "
 941                     eif-root-proc)))
 942
 943(defun eif-compile-internal ()
 944  "Compile an Eiffel root class.  Internal version.
 945Returns the same thing as \\[compilation-start] - the compilation buffer."
 946
 947  (let ((cmd (concat eif-se-command
 948                     " compile -flymake_mode "
 949                            eif-compile-options
 950                     " -o " eif-compile-target
 951                     (if (eq system-type 'windows-nt) ".exe")
 952                     " "    eif-root-class
 953                     " "    eif-root-proc))
 954        (buf-name "*Liberty Eiffel Compilation*")
 955        (compilation-mode-hook (cons 'eif-compilation-mode-hook
 956                                     compilation-mode-hook)))
 957    (if (fboundp 'compilation-start) ; Emacs 22 and above
 958        (compilation-start cmd nil #'(lambda (mode-name) buf-name))
 959      (compile-internal cmd "No more errors" buf-name))))
 960
 961(defun eif-run-internal ()
 962  "Run a compiled Eiffel program.  Internal version."
 963
 964  (let* ((tmp-buf (current-buffer))
 965         (words   (eif-split-string eif-run-command))
 966         (cmd     (expand-file-name (car words))))
 967
 968    (apply 'make-comint cmd cmd nil (cdr words))
 969    (switch-to-buffer tmp-buf)
 970    (switch-to-buffer-other-window (concat "*" cmd "*"))))
 971
 972;; This has been loosened up to spot parts of messages that contain
 973;; references to multiple locations.  Thanks to Andreas
 974;; <nozone@sbox.tu-graz.ac.at>.  Also, the column number is a character
 975;; count rather than a screen column, so we need to make sure that
 976;; compilation-error-screen-columns is nil.  Note that in XEmacs this
 977;; variable doesn't exist, so we end up in the wrong column.  Hey, at
 978;; least we're on the correct line!
 979(add-to-list 'compilation-error-regexp-alist
 980             '("^Line \\([0-9]+\\) column \\([0-9]+\\) in [^ ]+ (\\([^)]+\\.[Ee]\\))" 3 1 2))
 981
 982(defun eif-find-file (&optional userclass)
 983  "Find and open an Eiffel file given by a class name"
 984  (interactive)
 985  (let* ((cn (or userclass (current-word))))
 986    (if (string-match "[A-Z][0-9A-Z_]*" cn)
 987        (let ((classname (substring cn (match-beginning 0) (match-end 0))))
 988         (message "Searching %s..." classname)
 989         (let* ((shellres (shell-command-to-string (concat "se find --raw " classname)))
 990                (filename (substring shellres 0 (string-match "\n" shellres))))
 991           (find-file filename)
 992           )))
 993  (message nil)))
 994
 995(defun eif-short ()
 996  "Display the short form of an Eiffel class."
 997  (interactive)
 998  (let* ((class (read-string
 999                 "Class or file: "
1000                 (if (buffer-file-name)
1001                     (file-name-nondirectory (buffer-file-name)))))
1002         (buf (get-buffer-create (concat "*Eiffel - short " class "*"))))
1003
1004    (shell-command (concat eif-se-command " short " class) buf)
1005    (with-current-buffer buf
1006      (let ((font-lock-defaults eiffel-font-lock-defaults))
1007        (font-lock-fontify-buffer))
1008      (read-only-mode 1))))
1009
1010;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1011
1012;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1013;;                      Utility Functions.                      ;;
1014;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1015
1016(defun eif-feature-quote ()
1017  "Put a `' around the current feature name."
1018  (interactive)
1019  (save-excursion
1020    ;; Only try to go back to the beginning of the feature if we're
1021    ;; not already there.
1022    (if (/= (point)
1023            (save-excursion
1024              (forward-sexp)
1025              (backward-sexp)
1026              (point)))
1027        (backward-sexp))
1028    (insert "`")
1029    (forward-sexp)
1030    (insert "'"))
1031  (if (looking-at "'")
1032      (forward-char 1)))
1033
1034(defun eif-peeking-backwards-at (regexp)
1035  "Return non-nil is previous character exists and is matched by REGEXP.
1036The match is actually an unbounded match starting at the previous character."
1037  (save-excursion
1038    (save-match-data
1039      (and (not (bobp))
1040           (or (backward-char) t)
1041           (looking-at regexp)))))
1042
1043(defsubst eif-in-comment-p ()
1044  "Return t if point is in a comment."
1045  (interactive)
1046  (save-excursion
1047    (nth 4 (parse-partial-sexp
1048            (save-excursion (beginning-of-line) (point))
1049            (point)))))
1050
1051(defun eif-in-comment-or-quoted-string-p ()
1052  "Return t if point is in a comment or quoted string."
1053  (or (eif-in-comment-p)
1054      (eif-in-quoted-string-p)))
1055
1056(defun eif-not-in-comment-or-quoted-string-p ()
1057  "Return t if point is not in a comment or quoted string."
1058  (not (eif-in-comment-or-quoted-string-p)))
1059
1060(defun eif-near-comment-p ()
1061  "Return t if point is close enough to a comment for filling purposes."
1062  (or (eif-in-comment-p)
1063      (and (or (looking-at comment-start-skip)
1064               (eif-peeking-backwards-at comment-start-skip))
1065           (not (eif-in-quoted-string-p)))
1066      (looking-at (concat "[ \t]*" comment-start-skip))))
1067
1068(defun eif-re-search-forward (regexp &optional limit noerror)
1069  "Search forward from point for REGEXP not in comment or string.
1070`case-fold-search' is set to nil when searching.  For details on other
1071arguments see \\[re-search-forward]."
1072
1073  (interactive "sRE search: ")
1074  (let ((start (point))
1075        found case-fold-search)
1076    (while (and (setq found (re-search-forward regexp limit noerror))
1077                (eif-in-comment-or-quoted-string-p)))
1078    (if (and found
1079            (eif-not-in-comment-or-quoted-string-p))
1080        found
1081      (if (eq noerror t)
1082          (goto-char start))
1083      nil)))
1084
1085(defun eif-re-search-backward (regexp &optional limit noerror)
1086  "Search backward from point for REGEXP not in comment or string.
1087`case-fold-search' is set to nil when searching.  For details on other
1088arguments see \\[re-search-forward]."
1089  (interactive "sRE search: ")
1090  (let ((start (point))
1091        found case-fold-search)
1092    (while (and (setq found (re-search-backward regexp limit noerror))
1093                (eif-in-comment-or-quoted-string-p)))
1094    (if (and found
1095            (eif-not-in-comment-or-quoted-string-p))
1096        found
1097      (if (eq noerror t)
1098          (goto-char start))
1099      nil)))
1100
1101;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1102;;                      Indentation Functions.                  ;;
1103;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1104
1105(defun eif-skip-leading-whitespace ()
1106  "Move to the first non-whitespace character on the current line."
1107      (end-of-line)
1108      (let ((line-end (point)))
1109        (beginning-of-line)
1110        (skip-syntax-forward "-" line-end)))
1111
1112(defun eif-calc-indent ()
1113  "Calculate the indentation of the current line of eiffel code.
1114This function handles the case where there is a keyword that affects
1115indentation at the beginning of the current line.  For lines that
1116don't start with a relevant keyword, the calculation is handed off to
1117\\[eif-calc-non-keyword-indent]."
1118  (let ((indent   0)
1119        kw-match)
1120
1121    (save-excursion
1122      (eif-skip-leading-whitespace)
1123
1124      ;; Look for a keyword on the current line.
1125      (if (looking-at eif-all-keywords-regexp)
1126
1127          (cond ((looking-at eif-create-keyword-regexp)
1128                 ;; Class-level or minor occurence?
1129                 (if (save-excursion (eif-find-beginning-of-feature))
1130                     ;; Minor.
1131                     (setq indent (eif-calc-indent-non-keyword))
1132                   ;; Class-level.
1133                   (setq indent (eif-class-level-kw-indent-m))))
1134                ;; There's possibly a better way of coding this exception.
1135                ((looking-at eif-once-non-indent-regexp)
1136                 (setq indent (eif-calc-indent-non-keyword)))
1137                ((looking-at eif-indexing-keyword-regexp)
1138                 ;; Class-level or minor occurence?
1139                 (if (string-match eif-check-keyword (eif-matching-kw eif-check-keywords-regexp))
1140                     ;; In check.
1141                     (setq indent (+ eif-matching-indent (eif-check-keyword-indent-m)))
1142                   (if (save-excursion (eif-find-beginning-of-feature))
1143                       ;; Minor. (BUG: "note" can also be at the END of the class!!!)
1144                       (setq indent (eif-calc-indent-non-keyword))
1145                     ;; Class-level.
1146                     (setq indent (eif-class-level-kw-indent-m)))))
1147                ((looking-at eif-class-level-keywords-regexp)
1148                 ;; File level keywords (indent defaults to 0)
1149                 (setq indent (eif-class-level-kw-indent-m)))
1150                ((looking-at eif-inherit-level-keywords)
1151                 ;; Inherit level keywords (indent defaults to
1152                 ;; 2*eif-indent-increment)
1153                 (setq indent (eif-inherit-level-kw-indent-m)))
1154                ((looking-at eif-feature-level-keywords-regexp)
1155                 ;; Feature level keywords (indent defaults to
1156                 ;; (eif-feature-level-indent-m) + eif-indent-increment)
1157                 (setq indent (eif-feature-level-kw-indent-m)))
1158                ((looking-at eif-end-keyword)
1159                 ;; End keyword (indent to level of matching keyword)
1160                 (if (string-match "end"
1161                                   (eif-matching-kw
1162                                    eif-end-matching-keywords-regexp))
1163                     ;; Then
1164                     (if (= eif-matching-indent
1165                            (eif-feature-level-kw-indent-m))
1166                         ;; Then
1167                         (setq indent (eif-class-level-kw-indent-m))
1168                       ;; Else
1169                       (setq indent
1170                             (- eif-matching-indent eif-indent-increment)))
1171                   ;; Else
1172                   (setq indent eif-matching-indent))
1173                 ;; FIXME: This is broken!!!
1174                 (if (<= indent (eif-feature-level-indent-m))
1175                     (save-excursion
1176                       (end-of-line)
1177                       (while (and (< (point) (point-max))
1178                                   (or (forward-char 1) t)
1179                                   (looking-at eif-non-source-line))
1180                         (end-of-line))
1181                       (if (not (looking-at eif-non-source-line))
1182                           (setq indent (eif-inherit-level-kw-indent-m))
1183                         (setq indent (eif-class-level-kw-indent-m))))))
1184                ((looking-at eif-control-flow-keywords)
1185                 ;; Control flow keywords
1186                 ;;  Indent to same level as a preceding "end" or
1187                 ;;  if no preceding "end" is found, indent to the level
1188                 ;;  of the preceding "do" plus the value of
1189                 ;;  eif-indent-increment
1190                 (setq kw-match
1191                       (eif-matching-kw
1192                        eif-control-flow-matching-keywords-regexp))
1193                 (cond ((string-match "end" kw-match)
1194                        (setq indent eif-matching-indent))
1195                       (t
1196                        (setq indent
1197                              (+ eif-matching-indent eif-indent-increment)))))
1198                ((looking-at eif-check-keywords-regexp)
1199                 ;; Check keyword
1200                 ;;  Indent to level of preceding "end"+eif-indent-increment or
1201                 ;;  if no preceding "end" is found, indent to the level of
1202                 ;;  the preceding eif-check-matching-keywords-regexp plus the
1203                 ;;  value (eif-indent-increment + eif-check-keyword-indent).
1204
1205                 (setq kw-match (eif-matching-kw
1206                                 eif-check-matching-keywords-regexp))
1207                 (cond ((string-match "end" kw-match)
1208                        (setq indent (+ eif-matching-indent
1209                                        (eif-check-keyword-indent-m))))
1210                       (t
1211                        (setq indent
1212                              (+ eif-matching-indent
1213                                 (+ eif-indent-increment
1214                                    (eif-check-keyword-indent-m)))))))
1215                ((looking-at eif-rescue-keywords-regexp)
1216                 ;; Rescue keyword
1217                 ;;  Indent to level of preceding "end"+eif-indent-increment or
1218                 ;;  if no preceding "end" is found, indent to the level of
1219                 ;;  the preceding eif-rescue-matching-keywords-regexp plus the
1220                 ;;  value (eif-indent-increment + eif-rescue-keyword-indent).
1221                 (setq kw-match (eif-matching-kw
1222                                 eif-rescue-matching-keywords-regexp))
1223                 (cond ((string-match "end" kw-match)
1224                        (setq indent (+ eif-matching-indent
1225                                        (eif-rescue-keyword-indent-m))))
1226                       (t
1227                        (setq indent eif-matching-indent))))
1228                ((looking-at eif-from-level-keywords-regexp)
1229                 ;; From level keywords (indent to level of matching "From")
1230                 (if (string-match "end" (eif-matching-kw eif-from-keyword))
1231                     ;; Closest matching KW is `end'.
1232                     (setq indent (- eif-matching-indent eif-indent-increment))
1233                   ;; Closest matching KW is one of `eif-from-keyword'.
1234                   (setq indent eif-matching-indent)))
1235                ((looking-at eif-if-or-inspect-level-keywords-regexp)
1236                 ;; If level keywords (indent to level of matching
1237                 ;; "If" or "Inspect")
1238                 (if (string-match "end"
1239                                   (eif-matching-kw
1240                                    eif-if-or-inspect-keyword-regexp))
1241                     ;; Closest matching KW is `end'.
1242                     (setq indent (- eif-matching-indent eif-indent-increment))
1243                   ;; Closest matching KW is one of `eif-if-or-inspect-keyword-regexp'.
1244                   (setq indent eif-matching-indent)))
1245                ((looking-at eif-solitary-then-keyword)
1246                 ;; Handles case where "then" appears on a line by itself
1247                 (if (eif-matching-kw eif-then-matching-keywords t)
1248                     ;; (Indented to level of the matching if, elseif or when)
1249                     (setq indent (+ eif-matching-indent (eif-then-indent-m)))
1250                   (if (save-excursion (eif-find-beginning-of-feature))
1251                       ;; (Feature-level "then")
1252                       (setq indent (eif-feature-level-kw-indent-m))
1253                     (message "Non-matching 'then'")
1254                     (setq indent (eif-calc-indent-non-keyword)))))
1255                ((looking-at eif-invariant-keyword)
1256                 ;; Invariant keyword
1257                 ;;   (Indented to level of the matching from or feature)
1258                 (if (string-match "from"
1259                                   (eif-matching-kw eif-invariant-matchi

Large files files are truncated, but you can click here to view the full file