PageRenderTime 70ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. ;;; eiffel.el --- major mode for editing Eiffel files.
  2. ;; Copyright (C) 1989, 1990, 93, 94, 95, 96, 99, 2000, 01, 02, 03
  3. ;; Tower Technology Corporation,
  4. ;; Free Software Foundation,
  5. ;; Bob Weiner,
  6. ;; C. Adrian
  7. ;; Authors: 1989-1990 Stephen Omohundro, ISE and Bob Weiner
  8. ;; 1993-1996 Tower Technology Corporation
  9. ;; 1999-2003 Martin Schwenke <martin@meltin.net>
  10. ;; Maintainer: martin@meltin.net
  11. ;; Keywords: eiffel languages oop
  12. ;; Requires: font-lock, compile, easymenu, imenu
  13. ;; This file is derived from eiffel4.el from Tower Technology Corporation.
  14. ;;
  15. ;; Known bugs:
  16. ;;
  17. ;; * eif-short buffer doesn't get font locked under GNU Emacs 19.34.
  18. ;;
  19. ;; * eif-debug can hang under (at least) XEmacs 21.4.[89] in the wait
  20. ;; loop if there is input pending (that is, if the user hits return
  21. ;; an extra time). Not yet tested under XEmacs 21.5.
  22. ;;
  23. ;; This file is distributed under the same terms as GNU Emacs.
  24. ;; GNU Emacs is free software; you can redistribute it and/or modify
  25. ;; it under the terms of the GNU General Public License as published by
  26. ;; the Free Software Foundation; either version 2, or (at your option)
  27. ;; any later version.
  28. ;; GNU Emacs is distributed in the hope that it will be useful,
  29. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. ;; GNU General Public License for more details.
  32. ;; You should have received a copy of the GNU General Public License
  33. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  34. ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  35. ;; Boston, MA 02110-1301, USA
  36. ;;; Commentary:
  37. ;; NEW VERSIONS
  38. ;; The latest version of this mode is always available via:
  39. ;; http://meltin.net/hacks/emacs/
  40. ;; INSTALLATION
  41. ;; To install, simply copy this file into a directory in your
  42. ;; load-path and add the following two commands in your .emacs file:
  43. ;;
  44. ;; (add-to-list 'auto-mode-alist '("\\.e\\'" . eiffel-mode))
  45. ;; (autoload 'eiffel-mode "eiffel" "Major mode for Eiffel programs" t)
  46. ;;
  47. ;; Note: to be sure to have always a fresh eiffel.el, you can add the
  48. ;; "SmartEiffel/misc" directory in the emacs load-path by adding:
  49. ;;
  50. ;; (setq load-path (cons ".../SmartEiffel/misc" load-path))
  51. ;;; History:
  52. ;;
  53. ;; Add history stuff here!!!
  54. ;;; Code:
  55. (require 'font-lock)
  56. (require 'compile)
  57. (require 'easymenu)
  58. (require 'imenu)
  59. (defconst eiffel-version-string
  60. "$Id: eiffel.el,v 2.67 2003/06/14 10:41:01 martins Exp $"
  61. "Version string to make reporting bugs more meaningful.
  62. Note that if this file becomes part of GNU Emacs then the file might
  63. be changed by the Emacs maintainers without this version number
  64. changing. This means that if you are reporting a bug for a version
  65. that was shipped with Emacs, you should report the Emacs version!")
  66. (defgroup eiffel nil
  67. "Eiffel mode for Emacs"
  68. :group 'oop)
  69. (defgroup eiffel-indent nil
  70. "Indentation variables in Eiffel mode"
  71. :prefix "eif-"
  72. :group 'eiffel)
  73. (defgroup eiffel-compile nil
  74. "Compilation support variables in Eiffel mode"
  75. :prefix "eif-"
  76. :group 'eiffel)
  77. (defun eif-customize ()
  78. "Run \\[customize-group] for the `eiffel' group."
  79. (interactive)
  80. (customize-group 'eiffel))
  81. ;; Indentation amount variables.
  82. ;;
  83. ;; The default values correspond to style used in ``Eiffel: The
  84. ;; Language''.
  85. (defcustom eif-indent-increment 3
  86. "*Default indentation interval (in spaces)."
  87. :type 'integer
  88. :group 'eiffel-indent)
  89. (defcustom eif-class-level-kw-indent 0
  90. "*Indentation for Class level keywords.
  91. Specified as number of `eif-indent-increments'. See the variable
  92. `eif-class-level-keywords-regexp'."
  93. :type 'integer
  94. :group 'eiffel-indent)
  95. (defcustom eif-extra-class-level-kw-indent 0
  96. "*Number of extra spaces to add to `eif-class-level-kw-indent'.
  97. This results in the actual indentation of a class level keyword. Can
  98. be negative."
  99. :type 'integer
  100. :group 'eiffel-indent)
  101. (defcustom eif-class-level-comment-indent 0
  102. "*Indentation of comments at the beginning of a class.
  103. Specified as number of `eif-indent-increments'."
  104. :type 'integer
  105. :group 'eiffel-indent)
  106. (defcustom eif-extra-class-level-comment-indent 0
  107. "*Number of spaces to add to `eif-class-level-comment-indent'.
  108. This results in the actual indentation of a class level comment. Can
  109. be negative."
  110. :type 'integer
  111. :group 'eiffel-indent)
  112. (defcustom eif-inherit-level-kw-indent 2
  113. "*Indentation of keywords falling under the Inherit clause.
  114. Specified as number of `eif-indent-increments'. See the variable
  115. `eif-inherit-level-keywords'."
  116. :type 'integer
  117. :group 'eiffel-indent)
  118. (defcustom eif-extra-inherit-level-kw-indent 0
  119. "*Number of spaces to add to `eif-inherit-level-kw-indent'.
  120. This results in the actual indentation of an inherit level keyword.
  121. Can be negative."
  122. :type 'integer
  123. :group 'eiffel-indent)
  124. (defcustom eif-feature-level-indent 1
  125. "*Indentation amount of features.
  126. Specified as number of `eif-indent-increments'."
  127. :type 'integer
  128. :group 'eiffel-indent)
  129. (defcustom eif-extra-feature-level-indent 0
  130. "*Number of spaces to add to `eif-feature-level-indent'.
  131. This results in the indentation of a feature. Can be negative."
  132. :type 'integer
  133. :group 'eiffel-indent)
  134. (defcustom eif-feature-level-kw-indent 2
  135. "*Indentation of keywords belonging to individual features.
  136. Specified as number of `eif-indent-increments'. See the variable
  137. `eif-feature-level-keywords-regexp'."
  138. :type 'integer
  139. :group 'eiffel-indent)
  140. (defcustom eif-extra-feature-level-kw-indent 0
  141. "*Number of spaces to add to `eif-feature-level-kw-indent'.
  142. This results in the actual indentation of a feature level keyword.
  143. Can be negative."
  144. :type 'integer
  145. :group 'eiffel-indent)
  146. (defcustom eif-feature-level-comment-indent 3
  147. "*Indentation of comments at the beginning of a feature.
  148. Specified as number of `eif-indent-increments'."
  149. :type 'integer
  150. :group 'eiffel-indent)
  151. (defcustom eif-extra-feature-level-comment-indent 0
  152. "*Number of spaces to add to `eif-feature-level-comment-indent'.
  153. This results in the actual indentation of a feature level comment.
  154. Can be negative."
  155. :type 'integer
  156. :group 'eiffel-indent)
  157. (defcustom eif-body-comment-indent 0
  158. "*Indentation of comments in the body of a routine.
  159. Specified as number of `eif-indent-increments')"
  160. :type 'integer
  161. :group 'eiffel-indent)
  162. (defcustom eif-extra-body-comment-indent 0
  163. "*Number of spaces to add to `eif-body-comment-indent'.
  164. This results in the actual indentation of a routine body comment. Can
  165. be negative."
  166. :type 'integer
  167. :group 'eiffel-indent)
  168. (defcustom eif-check-keyword-indent 0
  169. "*Extra indentation for the check clause as described in ETL.
  170. Specified as number of `eif-indent-increments'. Default is 0, which
  171. is different than in ETL's 1."
  172. :type 'integer
  173. :group 'eiffel-indent)
  174. (defcustom eif-extra-check-keyword-indent 0
  175. "*Number of spaces to add to `eif-check-keyword-indent'.
  176. This results in the actual indentation of a check keyword. Can be
  177. negative."
  178. :type 'integer
  179. :group 'eiffel-indent)
  180. (defcustom eif-rescue-keyword-indent -1
  181. "*Extra indentation for the rescue clause as described in ETL.
  182. Specified as number of `eif-indent-increments'. Default is -1."
  183. :type 'integer
  184. :group 'eiffel-indent)
  185. (defcustom eif-extra-rescue-keyword-indent 0
  186. "*Number of spaces to add to `eif-rescue-keyword-indent'.
  187. This results in the actual indentation of a rescue keyword. Can be
  188. negative."
  189. :type 'integer
  190. :group 'eiffel-indent)
  191. (defcustom eif-then-indent 0
  192. "*Indentation for a `then' appearing on a line by itself.
  193. This is as opposed to a `then' on the same line as an `if'. Specified
  194. as number of `eif-indent-increments'."
  195. :type 'integer
  196. :group 'eiffel-indent)
  197. (defcustom eif-extra-then-indent 0
  198. "*Number of spaces to add to `eif-then-indent'.
  199. This results in the actual indentation of a `then' appearing on a line
  200. by itself. Can be negative."
  201. :type 'integer
  202. :group 'eiffel-indent)
  203. (defcustom eif-continuation-indent 1
  204. "*Extra indentation for a continued statement line.
  205. Specified as number of `eif-indent-increments'."
  206. :type 'integer
  207. :group 'eiffel-indent)
  208. (defcustom eif-extra-continuation-indent 0
  209. "*Number of spaces to add to `eif-continuation-indent'.
  210. This results in the actual indentation of a continued statement
  211. line. Can be negative."
  212. :type 'integer
  213. :group 'eiffel-indent)
  214. (defcustom eif-string-continuation-indent 0
  215. "*Extra indentation for a continued string.
  216. Specified as number of `eif-indent-increments'."
  217. :type 'integer
  218. :group 'eiffel-indent)
  219. (defcustom eif-extra-string-continuation-indent -1
  220. "*Number of spaces to add to `eif-string-continuation-indent'.
  221. This results in the actual indentation of a continued string. Can be
  222. negative."
  223. :type 'integer
  224. :group 'eiffel-indent)
  225. (defcustom eif-indent-string-continuations-relatively-flag t
  226. "*Non-nil means string continuations are indented relative to 1st character.
  227. That is, `eif-string-continuation-indent' and
  228. `eif-extra-string-continuation-indent' are added to position of first
  229. character of string. If nil, string continuations are indented
  230. relative to indent of previous line."
  231. :type 'boolean
  232. :group 'eiffel-indent)
  233. (defcustom eif-set-tab-width-flag t
  234. "*Non-nil means `tab-width' is set to `eif-indent-increment' in `eiffel-mode'."
  235. :type 'boolean
  236. :group 'eiffel-indent)
  237. (defcustom eif-preprocessor-indent 0
  238. "*Indentation for lines GOBO preprocessor directives.
  239. Specified as number of `eif-indent-increments' from left margin."
  240. :type 'integer
  241. :group 'eiffel-indent)
  242. (defcustom eif-fill-max-save 4096
  243. "*Maximum size of a paragraph to save before filling.
  244. Normally \\[eif-fill-paragraph] will mark a buffer as modified even if
  245. the fill operation does not make any changes. If the paragraph being
  246. filled is smaller than the value of this variable then the contents of
  247. the paragraph will be saved for comparison with the paragraph after
  248. the fill operation. If they are the same, the buffer modification
  249. state is restored. Set this to 0 to disable this feature, or a very
  250. big number to enable it for all paragraphs."
  251. :type 'integer
  252. :group 'eiffel-indent)
  253. (defcustom eif-use-gnu-eiffel t
  254. "*If t include support for compilation using GNU Liberty Eiffel."
  255. :type 'boolean
  256. :group 'eiffel-compile)
  257. (defcustom eif-se-command
  258. "se"
  259. "*Program to use for compiling Eiffel programs.
  260. The default is \"se\"."
  261. :type 'string
  262. :group 'eiffel-compile)
  263. (defcustom eif-compile-options ""
  264. "*Options to use for compiling Eiffel programs."
  265. :type 'string
  266. :group 'eiffel-compile)
  267. ;;
  268. ;; No user-customizable definitions below this point.
  269. ;;
  270. ;;
  271. ;; Indentation macros.
  272. ;;
  273. (defmacro eif-class-level-kw-indent-m ()
  274. "Indentation amount for Class level keywords (in number of spaces)."
  275. '(+ (* eif-class-level-kw-indent eif-indent-increment)
  276. eif-extra-class-level-kw-indent))
  277. (defmacro eif-class-level-comment-indent-m ()
  278. "Indentation amount for Class level comments (in number of spaces)."
  279. '(+ (* eif-class-level-comment-indent eif-indent-increment)
  280. eif-extra-class-level-comment-indent))
  281. (defmacro eif-inherit-level-kw-indent-m ()
  282. "Indentation amount for Inherit level keywords (in number of spaces)."
  283. '(+ (* eif-inherit-level-kw-indent eif-indent-increment)
  284. eif-extra-inherit-level-kw-indent))
  285. (defmacro eif-feature-level-indent-m ()
  286. "Indentation amount for features (in number of spaces)."
  287. '(+ (* eif-feature-level-indent eif-indent-increment)
  288. eif-extra-feature-level-indent))
  289. (defmacro eif-feature-level-kw-indent-m ()
  290. "Indentation amount for Feature level keywords (in number of spaces)."
  291. '(+ (* eif-feature-level-kw-indent eif-indent-increment)
  292. eif-extra-feature-level-kw-indent))
  293. (defmacro eif-body-comment-indent-m ()
  294. "Indentation amount for comments in routine bodies (in number of spaces)."
  295. '(+ (* eif-body-comment-indent eif-indent-increment)
  296. eif-extra-body-comment-indent))
  297. (defmacro eif-feature-level-comment-indent-m ()
  298. "Indentation amount for Feature level comments (in number of spaces)."
  299. '(+ (* eif-feature-level-comment-indent eif-indent-increment)
  300. eif-extra-feature-level-comment-indent))
  301. (defmacro eif-check-keyword-indent-m ()
  302. "Indentation amount for Check keyword (in number of spaces)."
  303. '(+ (* eif-check-keyword-indent eif-indent-increment)
  304. eif-extra-check-keyword-indent))
  305. (defmacro eif-rescue-keyword-indent-m ()
  306. "Indentation amount for Rescue keyword (in number of spaces)."
  307. '(+ (* eif-rescue-keyword-indent eif-indent-increment)
  308. eif-extra-rescue-keyword-indent))
  309. (defmacro eif-then-indent-m ()
  310. "Indentation amount for `then' appearing on a line by itself (in number of spaces)."
  311. '(+ (* eif-then-indent eif-indent-increment)
  312. eif-extra-then-indent))
  313. (defmacro eif-continuation-indent-m ()
  314. "Indentation amount for a statement continuation line (in number of spaces)."
  315. '(+ (* eif-continuation-indent eif-indent-increment)
  316. eif-extra-continuation-indent))
  317. (defmacro eif-string-continuation-indent-m ()
  318. "Indentation amount for a statement continuation line (in number of spaces)."
  319. '(+ (* eif-string-continuation-indent eif-indent-increment)
  320. eif-extra-string-continuation-indent))
  321. (defmacro eif-preprocessor-indent-m ()
  322. "Indentation amount for a preprocessor statement (in number of spaces)."
  323. '(* eif-preprocessor-indent eif-indent-increment))
  324. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  325. ;; Keyword Regular Expression Constants. ;;
  326. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  327. (defconst eif-non-id-char-regexp "\\S_" ;; "[^a-z0-9_]"
  328. "The characters that are not part of identifiers.")
  329. (defun eif-post-anchor (regexp)
  330. "Anchor given REGEXP with end-word delimiter and `eif-non-id-char-regexp'."
  331. (concat "\\(" regexp "\\)\\>" eif-non-id-char-regexp))
  332. (defun eif-word-anchor (regexp)
  333. "Anchor given REGEXP with word delimiters and `eif-non-id-char-regexp'."
  334. (concat "\\<\\(" regexp "\\)\\>" eif-non-id-char-regexp))
  335. (defun eif-anchor (regexp)
  336. "Anchor given REGEXP front and back to match line break or non-symbol char."
  337. (concat "\\(^\\|\\S_\\<\\)\\(" regexp "\\)\\($\\|\\>\\S_\\)"))
  338. ;; Note invariant is handled as a special case since it is both a
  339. ;; class-level and a from-level keyword
  340. ;; Note obsolete is handled as a special case since it is both a
  341. ;; class-level and a feature-level keyword
  342. ;; Note create, note, and indexing are also handled as special cases
  343. (defconst eif-class-level-keywords
  344. (concat
  345. "\\(?:"
  346. (regexp-opt '("deferred" "expanded" "reference" "separate"))
  347. "[ \t]+\\)?class"
  348. "\\|"
  349. (regexp-opt '("inherit" "insert" "convert" "creation" "feature")))
  350. "Keywords introducing class-level clauses.
  351. Note that `invariant', `obsolete', `indexing', `note', and `create' are not included here since can
  352. function as more than one type of keyword.")
  353. (defconst eif-class-level-keywords-regexp
  354. (eif-word-anchor eif-class-level-keywords)
  355. "Regexp of keywords introducing class level clauses, with some context.
  356. See `eif-class-level-keywords'.")
  357. (defconst eif-inherit-level-keywords
  358. (regexp-opt '("rename" "redefine" "undefine" "select" "export"))
  359. "Those keywords which introduce subclauses of the inherit clause.")
  360. (defconst eif-feature-level-keywords
  361. (regexp-opt '("require" "local" "deferred" "separate" "do" "once" "ensure" "alias" "external" "attribute"))
  362. "Those keywords which are internal to features (in particular, routines).")
  363. (defconst eif-feature-level-keywords-regexp
  364. (eif-word-anchor eif-feature-level-keywords)
  365. "Regexp of keywords internal to features (usually routines).
  366. See `eif-feature-level-keywords'.")
  367. (defconst eif-end-keyword "end" "The `end' keyword.")
  368. (defconst eif-end-on-current-line ".*[ \t]end[ \t]*;?[ \t]*\\(--.*\\)?$"
  369. "Regular expression to identify lines ending with the `end' keyword.")
  370. (defconst eif-control-flow-keywords
  371. (regexp-opt '("if" "inspect" "from" "debug"))
  372. "Keywords which introduce control-flow constructs.")
  373. (defconst eif-control-flow-matching-keywords
  374. (concat (regexp-opt '("deferred" "do" "once")) "\\|" eif-control-flow-keywords)
  375. "Keywords that may cause the indentation of an `eif-control-flow-keyword'.
  376. If these occur prior to an `eif-control-flow-keyword' then the
  377. `eif-control-flow-keyword' is indented. Note that technically, `end'
  378. is part of this list but it is handled separately in the function
  379. \[eif-matching-kw\].")
  380. (defconst eif-control-flow-matching-keywords-regexp
  381. (eif-word-anchor eif-control-flow-matching-keywords)
  382. "Regexp of keywords maybe causing indentation of `eif-control-flow-keyword'.
  383. See `eif-control-flow-keywords'.")
  384. (defconst eif-check-keyword "check"
  385. "The `check' keyword.")
  386. (defconst eif-check-keywords-regexp
  387. (eif-word-anchor eif-check-keyword)
  388. "The `check' keyword (with trailing context).")
  389. ;; FIXME: Doesn't work if once keyword is followed by a string on next
  390. ;; line, but didn't get broken by this attempt at factoring.
  391. (defconst eif-check-matching-keywords-regexp
  392. eif-control-flow-matching-keywords-regexp
  393. "Keywords that may cause the indentation of an `eif-check-keyword'.
  394. If these occur prior to an `eif-check-keyword' then the
  395. `eif-check-keyword' is indented. Note that technically, `end' is part
  396. of this list but it is handled separately in the function
  397. \[eif-matching-kw\]. See also `eif-control-flow-matching-keywords-regexp'.")
  398. ;; FIXME: This could be fixed or removed.
  399. (defconst eif-end-keyword-regexp "\\<end\\>"
  400. "The `end' keyword with context.")
  401. (defconst eif-end-matching-keywords
  402. (concat (regexp-opt '("attribute" "check" "class" "feature" "rename" "redefine" "undefine"
  403. "select" "export" "separate" "external" "alias")) "\\|"
  404. eif-control-flow-matching-keywords)
  405. "Those keywords whose clause is terminated by an `end' keyword.")
  406. (defconst eif-end-matching-keywords-regexp
  407. (eif-word-anchor eif-end-matching-keywords)
  408. "Regexp of keywords whose clause is terminated by an `end' keyword.
  409. See `eif-end-matching-keywords'.")
  410. (defconst eif-rescue-keyword "rescue" "The `rescue' keyword.")
  411. (defconst eif-obsolete-keyword "obsolete" "The `obsolete' keyword.")
  412. (defconst eif-indexing-keyword
  413. (regexp-opt '("note" "indexing"))
  414. "The `indexing' and `note' keywords.")
  415. (defconst eif-indexing-keyword-regexp
  416. (eif-post-anchor eif-indexing-keyword)
  417. "Regexp matching `indexing' and `note' keywords, with trailing context.")
  418. (defconst eif-rescue-keywords-regexp
  419. (eif-word-anchor eif-rescue-keyword)
  420. "The `rescue' keyword (with trailing context).")
  421. (defconst eif-rescue-matching-keywords-regexp
  422. (eif-word-anchor (regexp-opt '("deferred" "do" "once")))
  423. "Keywords that may cause the indentation of an `eif-rescue-keyword'.
  424. If these occur prior to an `eif-rescue-keyword' then the
  425. `eif-rescue-keyword' is indented. Note that technically, `end' is
  426. part of this list but it is handled separately in the function
  427. \[eif-matching-kw\]. See also `eif-control-flow-matching-keywords-regexp'.")
  428. (defconst eif-from-level-keywords
  429. (regexp-opt '("until" "variant" "loop"))
  430. "Keywords occuring inside of a from clause.")
  431. (defconst eif-from-level-keywords-regexp
  432. (eif-word-anchor eif-from-level-keywords)
  433. "Regexp of keywords occuring inside of a from clause.
  434. See `eif-from-level-keywords'.")
  435. (defconst eif-from-keyword "from" "The keyword `from'.")
  436. (defconst eif-if-or-inspect-level-keywords
  437. (regexp-opt '("elseif" "else" "when"))
  438. "Keywords occuring inside of an if or inspect clause.")
  439. (defconst eif-if-or-inspect-level-keywords-regexp
  440. (eif-word-anchor eif-if-or-inspect-level-keywords)
  441. "Regexp of keywords occuring inside of an if or inspect clause.
  442. See eif-if-or-inspect-level-keywords.")
  443. (defconst eif-if-or-inspect-keyword-regexp
  444. (eif-word-anchor (regexp-opt '("if" "inspect")))
  445. "Regexp matching the `if' or `inspect' keywords.")
  446. (defconst eif-then-keyword ".*[ \t)]then[ \t]*$"
  447. "The keyword `then' with possible leading text.")
  448. (defconst eif-solitary-then-keyword "then" "The keyword `then'.")
  449. (defconst eif-then-matching-keywords
  450. (regexp-opt '("if" "elseif" "when") t)
  451. "Keywords that may alter the indentation of an `eif-then-keyword'.
  452. If one of these occur prior to an `eif-then-keyword' then this sets
  453. the indentation of the `eif-then-keyword'. Note that technically,
  454. `end' is part of this list but it is handled separately in the
  455. function \[eif-matching-kw\]. See also
  456. `eif-control-flow-matching-keywords-regexp'.")
  457. (defconst eif-invariant-keyword "invariant" "The `invariant' keyword.")
  458. (defconst eif-invariant-matching-keywords
  459. (regexp-opt '("from" "feature"))
  460. "Keywords that may cause the indentation of an `eif-invarient-keyword'.
  461. If one of these occurs prior to an `eif-invariant-keyword' then the
  462. `eif-invariant-keyword' is indented. Note that technically, `end' is
  463. part of this list but it is handled separately in the function
  464. \[eif-matching-kw\]. See also `eif-control-flow-matching-keywords-regexp'.")
  465. (defconst eif-obsolete-matching-keywords
  466. (regexp-opt '("is" "class") t)
  467. "Keywords that may cause the indentation of an `eif-obsolete-keyword'.
  468. If one of these occurs prior to an `eif-obsolete-keyword' then the
  469. `eif-obsolete-keyword' is indented.")
  470. (defconst eif-create-keyword
  471. "create"
  472. "Eiffel create keyword. Can be used at class or minor level.")
  473. (defconst eif-create-keyword-regexp
  474. (eif-post-anchor eif-create-keyword)
  475. "Regexp matching `create' keyword, with trailing context.")
  476. (defconst eif-indentation-keywords
  477. (concat (regexp-opt '("note" "indexing" "rescue" "inherit" "insert" "convert" "create" "creation"
  478. "invariant" "require" "local" "ensure" "obsolete")) "\\|"
  479. eif-from-level-keywords "\\|"
  480. eif-if-or-inspect-level-keywords "\\|"
  481. eif-end-matching-keywords)
  482. "Keywords that match any eiffel keyword triggering indentation.")
  483. (defconst eif-indentation-keywords-regexp
  484. (eif-word-anchor eif-indentation-keywords)
  485. "Regexp of keywords that match any eiffel keyword triggering indentation.
  486. See `eif-indentation-keywords'.")
  487. (defconst eif-once-non-indent-regexp
  488. "\\s-*once\\(\\s-\\|\n\\)+\""
  489. "Regexp of Eiffel once keyword in context not affecting indentation.")
  490. (defconst eif-feature-indentation-keywords-regexp
  491. (eif-word-anchor (regexp-opt '("convert" "creation" "feature")))
  492. "Keywords which denote the presence of features following them.")
  493. (defconst eif-is-keyword-regexp "\\(.*[ \t)]\\)?is[ \t]*\\(--.*\\)?$"
  494. "The `is' keyword (with some context).")
  495. (defconst eif-multiline-routine-is-keyword-regexp
  496. ".*([^)]*)\\([ \t\n]*\\|[ \t\n]*:[][ \t\nA-Za-x0-9_,]*\\)is[ \t]*\\(--.*\\)?$"
  497. "The `is' keyword (with some context).")
  498. (defconst eif-operator-keywords
  499. (regexp-opt '("and" "or" "implies"))
  500. "Eiffel operator keywords.")
  501. (defconst eif-operator-regexp
  502. (concat "[ \t]*\\([@*/+]\\|-[^-]\\|\\<\\("
  503. eif-operator-keywords
  504. "\\)[ \t(]\\)")
  505. "Eiffel operators - used to identify continuation lines.
  506. See `eif-operator-keywords'.")
  507. (defconst eif-operator-eol-regexp
  508. (concat ".*\\([@*/+-]\\|\\<\\(" eif-operator-keywords
  509. "\\)\\|:=\\)[ \t]*\\(--.*\\)?$")
  510. "Eiffel operators - used to identify continuation lines.")
  511. (defconst eif-all-keywords
  512. (concat eif-indentation-keywords "\\|"
  513. eif-solitary-then-keyword "\\|"
  514. eif-create-keyword "\\|"
  515. eif-end-keyword)
  516. "Regexp matching (nearly) any eiffel keyword in a line.
  517. Does not include `is'.")
  518. (defconst eif-all-keywords-regexp
  519. (concat "\\("
  520. (eif-word-anchor eif-all-keywords) "\\)")
  521. "Anchored regexp matching (nearly) any eiffel keyword in a line.
  522. Does not include `is'. See `eif-all-keywords'.")
  523. (defconst eiffel-comment-start-skip
  524. "--+|?[ \t]*"
  525. "Regexp matching the beginning of an Eiffel comment.")
  526. (defconst eif-non-source-line
  527. (concat "[ \t]*\\(\\(" "--" "\\).*\\)?$")
  528. "RE matching line with only whitespace and comment or preprocessor keyword.")
  529. (defconst eif-variable-or-const-regexp "[^()\n]*:[^=].*"
  530. "RE to match a variable or constant declaration.")
  531. ;; Factor out some important important regexps for use in
  532. ;; eif-{beginning,end}-of-feature.
  533. (defun eiffel-feature-re ()
  534. "Liberty Eiffel feature declarations"
  535. (let* ((argument-name "\\(?:[A-Za-z]*[a-z0-9_]+[A-Za-z0-9_]*\\)")
  536. (feature-name (concat "\\(?:\\(infix\\|prefix\\)\\s-+\".+?\"\\|" argument-name "\\(?:\\s-+alias\\s-+\".+?\"\\)?\\)"))
  537. (type-name "\\(?:like\\s-+\\sw+\\|[A-Z]\\sw*\\(?:\\[.+?\\]\\)?\\)"))
  538. (concat
  539. "\\(?:"
  540. "\\(?:\\<frozen\\s-\\)?"
  541. "\\s-*" feature-name "\\s-*,?"
  542. "\\)+"
  543. "\\(?:(" ; no \\s-* because it is matched above, if there is no trailing coma
  544. "\\(?:"
  545. "\\(?:\\s-*" argument-name "\\s-*,?\\)+?"
  546. ":" type-name "\\s-*;?"
  547. "\\)*?"
  548. ")\\)?" ; no \\s-* because it is matched above, if there is no trailing semi-colon
  549. "\\(?:\\s-*:\\s-*" type-name "\\)?"
  550. "\\(?:\\s-*assign\\s-*\\sw+\\)?"
  551. "\\(?:\\s-*is\\>\\)?")))
  552. (defconst eif-routine-begin-regexp
  553. ;"\\([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-*\\(--.*\\)?$"
  554. (eiffel-feature-re)
  555. "Regexp matching the beginning of an Eiffel routine declaration.")
  556. (message (concat "Liberty Eiffel features: " eif-routine-begin-regexp))
  557. (defconst eif-attribute-regexp
  558. (concat "[a-z_][^-:\n]*:\\s-*"
  559. "\\(like\\s-*[a-zA-Z][a-z_0-9]*\\|"
  560. "\\(\\(expanded\\|reference\\)\\s-*\\)?[A-Z][A-Z_0-9]*"
  561. "\\(\\s-*\\[[^-\n]*\\]\\)?\\)"
  562. "\\s-*\\($\\|[;)].*\\|--.*\\)")
  563. "Regexp matching an Eiffel attribute, parameter or local variable.")
  564. (defconst eif-constant-regexp
  565. "[a-z_][^-:\n]*:[^-\n]*\\<is\\>\\s-*[^ \t\n]"
  566. "Regexp matching an Eiffel constant declaration.")
  567. (defconst eif-probably-feature-regexp
  568. (concat "\\(" eif-routine-begin-regexp
  569. "\\|" eif-attribute-regexp
  570. "\\|" eif-constant-regexp "\\)")
  571. "Regexp probably matching an Eiffel feature.
  572. This will also match local variable and parameter declarations.")
  573. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  574. (defvar eif-matching-indent -1
  575. "Indentation of the keyword found on the last call to \[eif-matching-kw\].
  576. -1 if no match was found.")
  577. (defvar eif-matching-kw-for-end nil)
  578. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  579. ;;
  580. ;; Font-lock support.
  581. ;;
  582. ;; Rewritten from scratch by Cyril Adrian <cyril.adrian@gmail.com>
  583. ;; Specific to Liberty Eiffel
  584. ;;
  585. (defconst eiffel-keywords-feature
  586. '("agent" "all" "and" "as" "assign" "attribute" "check" "class"
  587. "convert" "create" "debug" "deferred" "do" "else" "elseif" "end" "ensure"
  588. "expanded" "export" "external" "feature" "from" "if" "implies"
  589. "indexing" "inherit" "insert" "inspect" "invariant" "is" "like"
  590. "local" "loop" "not" "note" "obsolete" "old" "once" "only" "or"
  591. "redefine" "rename" "require" "rescue" "retry" "select" "separate" "then"
  592. "undefine" "until" "variant" "when" "xor"))
  593. (defconst eiffel-keywords
  594. '("agent" "alias" "all" "and" "as" "assign" "attribute" "check" "class"
  595. "convert" "create" "debug" "deferred" "do" "else" "elseif" "end" "ensure"
  596. "expanded" "export" "external" "feature" "from" "frozen" "if" "implies"
  597. "indexing" "infix" "inherit" "insert" "inspect" "invariant" "is" "like"
  598. "local" "loop" "not" "note" "obsolete" "old" "once" "only" "or" "prefix"
  599. "redefine" "rename" "require" "rescue" "retry" "select" "separate" "then"
  600. "undefine" "until" "variant" "when" "xor"))
  601. (defconst eiffel-constants
  602. '("Current" "False" "Precursor" "Result" "True" "Void"))
  603. (defun eiffel-string-re ()
  604. "Liberty Eiffel strings"
  605. (concat "U?\"\\(?:"
  606. "\\(?:\\(?:[^%\"\n]\\|%[^\n]\\)*?\\)" ; single-line strings
  607. "\\|"
  608. "\\(?:\\(?:[^%\"\n]\\|%[^\n]\\)*?%[ \t]*\n\\(?:[ \t]*%\\(?:[^%\"\n]\\|%[^\n]\\)*?%[ \t]*\n\\)*[ \t]*%\\(?:[^%\"\n]\\|%[^\n]\\)*?\\)" ; older multiline strings
  609. "\\|"
  610. "\\(?:[[{][ \t]*\n\\(?:.*?\n\\)*?[ \t]*[]}]\"\\)" ; newer multiline strings
  611. "\\)\""))
  612. (defun eiffel-wordstart-re ()
  613. "start of words"
  614. "\\<\\(")
  615. (defun eiffel-wordend-re ()
  616. "end of words"
  617. (concat "\\)\\>"))
  618. (defun eiffel-keywords-re ()
  619. (concat
  620. (eiffel-wordstart-re)
  621. (regexp-opt eiffel-keywords)
  622. (eiffel-wordend-re)))
  623. (defun eiffel-constants-re ()
  624. (concat
  625. (eiffel-wordstart-re)
  626. (regexp-opt eiffel-constants)
  627. (eiffel-wordend-re)))
  628. (defun eiffel-preprocessor-re ()
  629. (concat
  630. (eiffel-wordstart-re)
  631. (regexp-opt '("c_inline_c" "c_inline_h" "not_yet_implemented" "se_breakpoint" "breakpoint" "to_pointer"
  632. "is_expanded_type" "is_basic_expanded_type"
  633. "object_size" "object_id_memory"
  634. "se_guru01" "se_guru02" "se_guru03"))
  635. (eiffel-wordend-re)))
  636. (defvar eiffel-font-lock-defaults
  637. (append
  638. `(
  639. ("--|\\(.*\\)\n" . font-lock-comment-face)
  640. ("--\\(.*\\)\n" . font-lock-doc-face)
  641. (,(eiffel-string-re) . font-lock-string-face)
  642. ("'\\(?:[^'%]\\|%.\\)'" . font-lock-string-face)
  643. ("\\<\\([A-Z][A-Z0-9_]*\\)\\>" . font-lock-type-face)
  644. (,(eiffel-keywords-re) 1 font-lock-keyword-face)
  645. (,(eiffel-constants-re) 1 font-lock-builtin-face)
  646. (,(eiffel-preprocessor-re) 1 font-lock-preprocessor-face)))
  647. "Default highlighting expressions for Liberty Eiffel mode")
  648. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  649. ;;
  650. ;; Compilation support for GNU SmartEiffel.
  651. ;;
  652. (defvar eif-compile-dir nil
  653. "Current directory where Eiffel compilations are taking place.
  654. Possibly used for error location.")
  655. (defvar eif-root-class nil
  656. "Current Eiffel root class being compiled/debugged.")
  657. (defvar eif-compile-target nil
  658. "Current Eiffel compilation target.")
  659. (defvar eif-debug-target nil
  660. "Current Eiffel debug target.")
  661. (defvar eif-root-proc nil
  662. "Current Eiffel root procedure.")
  663. (defvar eif-run-command nil
  664. "Current command to run after Eiffel compile.")
  665. (defvar eif-debug-command nil
  666. "Current debug command to run after Eiffel debug compile.")
  667. (defun eif-compilation-mode-hook ()
  668. "Hook function to set local value for `compilation-error-screen-columns'.
  669. This should be nil for SmartEiffel compiles, because column positions are
  670. returned as character positions rather than screen columns."
  671. ;; In Emacs > 20.7 compilation-error-screen-columns is buffer local.
  672. (or (assq 'compilation-error-screen-columns (buffer-local-variables))
  673. (make-local-variable 'compilation-error-screen-columns))
  674. (setq compilation-error-screen-columns nil))
  675. (defun eif-compile ()
  676. "Compile an Eiffel root class."
  677. (interactive)
  678. (eif-compile-prompt)
  679. (eif-compile-internal))
  680. (defun eif-set-compile-options ()
  681. "Set Eiffel compiler options."
  682. (interactive)
  683. (setq eif-compile-options
  684. (read-string "Eiffel compiler options: " eif-compile-options)))
  685. ;; Taken from Emacs 20.3 subr.el (just in case we're running under Emacs 19).
  686. (defun eif-split-string (string &optional separators)
  687. "Split STRING into substrings separated by SEPARATORS.
  688. Each match for SEPARATORS is a splitting point. The substrings
  689. between the splitting points are made into a list which is returned.
  690. If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\".
  691. If there is match for SEPARATORS at the beginning of STRING, we do not
  692. include a null substring for that. Likewise, if there is a match
  693. at the end of STRING, we do not include a null substring for that."
  694. (let ((rexp (or separators "[ \f\t\n\r\v]+"))
  695. (start 0)
  696. notfirst
  697. (list nil))
  698. (while (and (string-match rexp string
  699. (if (and notfirst
  700. (= start (match-beginning 0))
  701. (< start (length string)))
  702. (1+ start) start))
  703. (< (match-beginning 0) (length string)))
  704. (setq notfirst t)
  705. (or (eq (match-beginning 0) 0)
  706. (and (eq (match-beginning 0) (match-end 0))
  707. (eq (match-beginning 0) start))
  708. (setq list
  709. (cons (substring string start (match-beginning 0))
  710. list)))
  711. (setq start (match-end 0)))
  712. (or (eq start (length string))
  713. (setq list
  714. (cons (substring string start)
  715. list)))
  716. (nreverse list)))
  717. (defun eif-run ()
  718. "Run a compiled Eiffel program."
  719. (interactive)
  720. (setq eif-run-command
  721. (read-string "Command to run: "
  722. (or eif-run-command
  723. eif-compile-target
  724. (file-name-sans-extension
  725. (if (or (eq system-type 'windows-nt) (eq system-type 'cygwin))
  726. buffer-file-name
  727. (file-name-nondirectory (buffer-file-name)))))))
  728. (eif-run-internal))
  729. (defun eif-debug ()
  730. "Run the SmartEiffel debugger."
  731. (interactive)
  732. (eif-compile-prompt)
  733. (setq eif-debug-target
  734. (file-name-sans-extension
  735. (read-string "Debug target name: "
  736. (or eif-debug-target
  737. (concat eif-compile-target "_debug")))))
  738. (let* ((eif-compile-options (concat "-sedb " eif-compile-options))
  739. (eif-compile-target eif-debug-target)
  740. (buff (eif-compile-internal))
  741. (proc (get-buffer-process buff)))
  742. ;; This works under GNU Emacs, but hangs under at least some
  743. ;; versions of XEmacs if there is input pending.
  744. (while (eq (process-status proc) 'run)
  745. (sit-for 1))
  746. (if (= (process-exit-status proc) 0)
  747. (progn
  748. (setq eif-debug-command
  749. (read-string "Debugger command to run: "
  750. (or eif-debug-command
  751. eif-debug-target
  752. (file-name-sans-extension
  753. (if (eq system-type 'windows-nt)
  754. buffer-file-name
  755. (file-name-nondirectory
  756. (buffer-file-name)))))))
  757. (let ((eif-run-command eif-debug-command))
  758. (eif-run-internal))))))
  759. (defun eif-compile-prompt ()
  760. "Prompt for information required to compile an Eiffel root class."
  761. ;; Do the save first, since the user might still have their hand on
  762. ;; the mouse.
  763. (save-some-buffers (not compilation-ask-about-save) nil)
  764. (setq eif-compile-dir (file-name-directory (buffer-file-name)))
  765. (setq eif-root-class
  766. (file-name-sans-extension
  767. (read-string "Name of root class: "
  768. (or eif-compile-target
  769. (file-name-sans-extension
  770. (file-name-nondirectory (buffer-file-name)))))))
  771. (setq eif-compile-target eif-root-class)
  772. (setq eif-root-proc
  773. (read-string "Name of root procedure: "
  774. eif-root-proc)))
  775. (defun eif-compile-internal ()
  776. "Compile an Eiffel root class. Internal version.
  777. Returns the same thing as \\[compilation-start] - the compilation buffer."
  778. (let ((cmd (concat eif-se-command
  779. " compile -flymake_mode "
  780. eif-compile-options
  781. " -o " eif-compile-target
  782. (if (eq system-type 'windows-nt) ".exe")
  783. " " eif-root-class
  784. " " eif-root-proc))
  785. (buf-name "*Liberty Eiffel Compilation*")
  786. (compilation-mode-hook (cons 'eif-compilation-mode-hook
  787. compilation-mode-hook)))
  788. (if (fboundp 'compilation-start) ; Emacs 22 and above
  789. (compilation-start cmd nil #'(lambda (mode-name) buf-name))
  790. (compile-internal cmd "No more errors" buf-name))))
  791. (defun eif-run-internal ()
  792. "Run a compiled Eiffel program. Internal version."
  793. (let* ((tmp-buf (current-buffer))
  794. (words (eif-split-string eif-run-command))
  795. (cmd (expand-file-name (car words))))
  796. (apply 'make-comint cmd cmd nil (cdr words))
  797. (switch-to-buffer tmp-buf)
  798. (switch-to-buffer-other-window (concat "*" cmd "*"))))
  799. ;; This has been loosened up to spot parts of messages that contain
  800. ;; references to multiple locations. Thanks to Andreas
  801. ;; <nozone@sbox.tu-graz.ac.at>. Also, the column number is a character
  802. ;; count rather than a screen column, so we need to make sure that
  803. ;; compilation-error-screen-columns is nil. Note that in XEmacs this
  804. ;; variable doesn't exist, so we end up in the wrong column. Hey, at
  805. ;; least we're on the correct line!
  806. (add-to-list 'compilation-error-regexp-alist
  807. '("^Line \\([0-9]+\\) column \\([0-9]+\\) in [^ ]+ (\\([^)]+\\.[Ee]\\))" 3 1 2))
  808. (defun eif-find-file (&optional userclass)
  809. "Find and open an Eiffel file given by a class name"
  810. (interactive)
  811. (let* ((cn (or userclass (current-word))))
  812. (if (string-match "[A-Z][0-9A-Z_]*" cn)
  813. (let ((classname (substring cn (match-beginning 0) (match-end 0))))
  814. (message "Searching %s..." classname)
  815. (let* ((shellres (shell-command-to-string (concat "se find --raw " classname)))
  816. (filename (substring shellres 0 (string-match "\n" shellres))))
  817. (find-file filename)
  818. )))
  819. (message nil)))
  820. (defun eif-short ()
  821. "Display the short form of an Eiffel class."
  822. (interactive)
  823. (let* ((class (read-string
  824. "Class or file: "
  825. (if (buffer-file-name)
  826. (file-name-nondirectory (buffer-file-name)))))
  827. (buf (get-buffer-create (concat "*Eiffel - short " class "*"))))
  828. (shell-command (concat eif-se-command " short " class) buf)
  829. (with-current-buffer buf
  830. (let ((font-lock-defaults eiffel-font-lock-defaults))
  831. (font-lock-fontify-buffer))
  832. (read-only-mode 1))))
  833. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  834. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  835. ;; Utility Functions. ;;
  836. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  837. (defun eif-feature-quote ()
  838. "Put a `' around the current feature name."
  839. (interactive)
  840. (save-excursion
  841. ;; Only try to go back to the beginning of the feature if we're
  842. ;; not already there.
  843. (if (/= (point)
  844. (save-excursion
  845. (forward-sexp)
  846. (backward-sexp)
  847. (point)))
  848. (backward-sexp))
  849. (insert "`")
  850. (forward-sexp)
  851. (insert "'"))
  852. (if (looking-at "'")
  853. (forward-char 1)))
  854. (defun eif-peeking-backwards-at (regexp)
  855. "Return non-nil is previous character exists and is matched by REGEXP.
  856. The match is actually an unbounded match starting at the previous character."
  857. (save-excursion
  858. (save-match-data
  859. (and (not (bobp))
  860. (or (backward-char) t)
  861. (looking-at regexp)))))
  862. (defsubst eif-in-comment-p ()
  863. "Return t if point is in a comment."
  864. (interactive)
  865. (save-excursion
  866. (nth 4 (parse-partial-sexp
  867. (save-excursion (beginning-of-line) (point))
  868. (point)))))
  869. (defun eif-in-comment-or-quoted-string-p ()
  870. "Return t if point is in a comment or quoted string."
  871. (or (eif-in-comment-p)
  872. (eif-in-quoted-string-p)))
  873. (defun eif-not-in-comment-or-quoted-string-p ()
  874. "Return t if point is not in a comment or quoted string."
  875. (not (eif-in-comment-or-quoted-string-p)))
  876. (defun eif-near-comment-p ()
  877. "Return t if point is close enough to a comment for filling purposes."
  878. (or (eif-in-comment-p)
  879. (and (or (looking-at comment-start-skip)
  880. (eif-peeking-backwards-at comment-start-skip))
  881. (not (eif-in-quoted-string-p)))
  882. (looking-at (concat "[ \t]*" comment-start-skip))))
  883. (defun eif-re-search-forward (regexp &optional limit noerror)
  884. "Search forward from point for REGEXP not in comment or string.
  885. `case-fold-search' is set to nil when searching. For details on other
  886. arguments see \\[re-search-forward]."
  887. (interactive "sRE search: ")
  888. (let ((start (point))
  889. found case-fold-search)
  890. (while (and (setq found (re-search-forward regexp limit noerror))
  891. (eif-in-comment-or-quoted-string-p)))
  892. (if (and found
  893. (eif-not-in-comment-or-quoted-string-p))
  894. found
  895. (if (eq noerror t)
  896. (goto-char start))
  897. nil)))
  898. (defun eif-re-search-backward (regexp &optional limit noerror)
  899. "Search backward from point for REGEXP not in comment or string.
  900. `case-fold-search' is set to nil when searching. For details on other
  901. arguments see \\[re-search-forward]."
  902. (interactive "sRE search: ")
  903. (let ((start (point))
  904. found case-fold-search)
  905. (while (and (setq found (re-search-backward regexp limit noerror))
  906. (eif-in-comment-or-quoted-string-p)))
  907. (if (and found
  908. (eif-not-in-comment-or-quoted-string-p))
  909. found
  910. (if (eq noerror t)
  911. (goto-char start))
  912. nil)))
  913. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  914. ;; Indentation Functions. ;;
  915. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  916. (defun eif-skip-leading-whitespace ()
  917. "Move to the first non-whitespace character on the current line."
  918. (end-of-line)
  919. (let ((line-end (point)))
  920. (beginning-of-line)
  921. (skip-syntax-forward "-" line-end)))
  922. (defun eif-calc-indent ()
  923. "Calculate the indentation of the current line of eiffel code.
  924. This function handles the case where there is a keyword that affects
  925. indentation at the beginning of the current line. For lines that
  926. don't start with a relevant keyword, the calculation is handed off to
  927. \\[eif-calc-non-keyword-indent]."
  928. (let ((indent 0)
  929. kw-match)
  930. (save-excursion
  931. (eif-skip-leading-whitespace)
  932. ;; Look for a keyword on the current line.
  933. (if (looking-at eif-all-keywords-regexp)
  934. (cond ((looking-at eif-create-keyword-regexp)
  935. ;; Class-level or minor occurence?
  936. (if (save-excursion (eif-find-beginning-of-feature))
  937. ;; Minor.
  938. (setq indent (eif-calc-indent-non-keyword))
  939. ;; Class-level.
  940. (setq indent (eif-class-level-kw-indent-m))))
  941. ;; There's possibly a better way of coding this exception.
  942. ((looking-at eif-once-non-indent-regexp)
  943. (setq indent (eif-calc-indent-non-keyword)))
  944. ((looking-at eif-indexing-keyword-regexp)
  945. ;; Class-level or minor occurence?
  946. (if (string-match eif-check-keyword (eif-matching-kw eif-check-keywords-regexp))
  947. ;; In check.
  948. (setq indent (+ eif-matching-indent (eif-check-keyword-indent-m)))
  949. (if (save-excursion (eif-find-beginning-of-feature))
  950. ;; Minor. (BUG: "note" can also be at the END of the class!!!)
  951. (setq indent (eif-calc-indent-non-keyword))
  952. ;; Class-level.
  953. (setq indent (eif-class-level-kw-indent-m)))))
  954. ((looking-at eif-class-level-keywords-regexp)
  955. ;; File level keywords (indent defaults to 0)
  956. (setq indent (eif-class-level-kw-indent-m)))
  957. ((looking-at eif-inherit-level-keywords)
  958. ;; Inherit level keywords (indent defaults to
  959. ;; 2*eif-indent-increment)
  960. (setq indent (eif-inherit-level-kw-indent-m)))
  961. ((looking-at eif-feature-level-keywords-regexp)
  962. ;; Feature level keywords (indent defaults to
  963. ;; (eif-feature-level-indent-m) + eif-indent-increment)
  964. (setq indent (eif-feature-level-kw-indent-m)))
  965. ((looking-at eif-end-keyword)
  966. ;; End keyword (indent to level of matching keyword)
  967. (if (string-match "end"
  968. (eif-matching-kw
  969. eif-end-matching-keywords-regexp))
  970. ;; Then
  971. (if (= eif-matching-indent
  972. (eif-feature-level-kw-indent-m))
  973. ;; Then
  974. (setq indent (eif-class-level-kw-indent-m))
  975. ;; Else
  976. (setq indent
  977. (- eif-matching-indent eif-indent-increment)))
  978. ;; Else
  979. (setq indent eif-matching-indent))
  980. ;; FIXME: This is broken!!!
  981. (if (<= indent (eif-feature-level-indent-m))
  982. (save-excursion
  983. (end-of-line)
  984. (while (and (< (point) (point-max))
  985. (or (forward-char 1) t)
  986. (looking-at eif-non-source-line))
  987. (end-of-line))
  988. (if (not (looking-at eif-non-source-line))
  989. (setq indent (eif-inherit-level-kw-indent-m))
  990. (setq indent (eif-class-level-kw-indent-m))))))
  991. ((looking-at eif-control-flow-keywords)
  992. ;; Control flow keywords
  993. ;; Indent to same level as a preceding "end" or
  994. ;; if no preceding "end" is found, indent to the level
  995. ;; of the preceding "do" plus the value of
  996. ;; eif-indent-increment
  997. (setq kw-match
  998. (eif-matching-kw
  999. eif-control-flow-matching-keywords-regexp))
  1000. (cond ((string-match "end" kw-match)
  1001. (setq indent eif-matching-indent))
  1002. (t
  1003. (setq indent
  1004. (+ eif-matching-indent eif-indent-increment)))))
  1005. ((looking-at eif-check-keywords-regexp)
  1006. ;; Check keyword
  1007. ;; Indent to level of preceding "end"+eif-indent-increment or
  1008. ;; if no preceding "end" is found, indent to the level of
  1009. ;; the preceding eif-check-matching-keywords-regexp plus the
  1010. ;; value (eif-indent-increment + eif-check-keyword-indent).
  1011. (setq kw-match (eif-matching-kw
  1012. eif-check-matching-keywords-regexp))
  1013. (cond ((string-match "end" kw-match)
  1014. (setq indent (+ eif-matching-indent
  1015. (eif-check-keyword-indent-m))))
  1016. (t
  1017. (setq indent
  1018. (+ eif-matching-indent
  1019. (+ eif-indent-increment
  1020. (eif-check-keyword-indent-m)))))))
  1021. ((looking-at eif-rescue-keywords-regexp)
  1022. ;; Rescue keyword
  1023. ;; Indent to level of preceding "end"+eif-indent-increment or
  1024. ;; if no preceding "end" is found, indent to the level of
  1025. ;; the preceding eif-rescue-matching-keywords-regexp plus the
  1026. ;; value (eif-indent-increment + eif-rescue-keyword-indent).
  1027. (setq kw-match (eif-matching-kw
  1028. eif-rescue-matching-keywords-regexp))
  1029. (cond ((string-match "end" kw-match)
  1030. (setq indent (+ eif-matching-indent
  1031. (eif-rescue-keyword-indent-m))))
  1032. (t
  1033. (setq indent eif-matching-indent))))
  1034. ((looking-at eif-from-level-keywords-regexp)
  1035. ;; From level keywords (indent to level of matching "From")
  1036. (if (string-match "end" (eif-matching-kw eif-from-keyword))
  1037. ;; Closest matching KW is `end'.
  1038. (setq indent (- eif-matching-indent eif-indent-increment))
  1039. ;; Closest matching KW is one of `eif-from-keyword'.
  1040. (setq indent eif-matching-indent)))
  1041. ((looking-at eif-if-or-inspect-level-keywords-regexp)
  1042. ;; If level keywords (indent to level of matching
  1043. ;; "If" or "Inspect")
  1044. (if (string-match "end"
  1045. (eif-matching-kw
  1046. eif-if-or-inspect-keyword-regexp))
  1047. ;; Closest matching KW is `end'.
  1048. (setq indent (- eif-matching-indent eif-indent-increment))
  1049. ;; Closest matching KW is one of `eif-if-or-inspect-keyword-regexp'.
  1050. (setq indent eif-matching-indent)))
  1051. ((looking-at eif-solitary-then-keyword)
  1052. ;; Handles case where "then" appears on a line by itself
  1053. (if (eif-matching-kw eif-then-matching-keywords t)
  1054. ;; (Indented to level of the matching if, elseif or when)
  1055. (setq indent (+ eif-matching-indent (eif-then-indent-m)))
  1056. (if (save-excursion (eif-find-beginning-of-feature))
  1057. ;; (Feature-level "then")
  1058. (setq indent (eif-feature-level-kw-indent-m))
  1059. (message "Non-matching 'then'")
  1060. (setq indent (eif-calc-indent-non-keyword)))))
  1061. ((looking-at eif-invariant-keyword)
  1062. ;; Invariant keyword
  1063. ;; (Indented to level of the matching from or feature)
  1064. (if (string-match "from"
  1065. (eif-matching-kw eif-invariant-matching-keywords))
  1066. ;; Then - loop invariant
  1067. (setq indent eif-matching-indent)
  1068. ;; Else - class invariant
  1069. (setq indent (eif-class-level-kw-indent-m))))
  1070. ((looking-at eif-obsolete-keyword)
  1071. ;; Obsolete keyword
  1072. ;; (Indented to the level of the matching from or feature)
  1073. (if (string-match "class"
  1074. (eif-matching-kw eif-obsolete-matching-keywords))
  1075. ;; Then - class obsolete
  1076. (setq indent (eif-class-level-kw-indent-m))
  1077. ;; Else - feature obsolete
  1078. (setq indent (eif-feature-level-kw-indent-m)))))
  1079. ;; No keyword. Hand off...
  1080. (setq indent (eif-calc-indent-non-keyword))))
  1081. indent))
  1082. (defun eif-calc-indent-non-keyword ()
  1083. "Calculate indentation of current Eiffel code line, without leading keyword.
  1084. This function generally assumes that the preceding line of code is
  1085. indented properly, and usually bases the indentation of the current
  1086. line on that preceding line."
  1087. (let ((indent 0)
  1088. originally-looking-at-comment originally-looking-at-lone-string
  1089. continuation id-colon)
  1090. (save-excursion
  1091. (eif-skip-leading-whitespace)
  1092. ;; Is the line we are trying to indent a comment line?
  1093. (setq originally-looking-at-comment (looking-at comment-start-skip))
  1094. ;; Is the line we are trying to indent a lone string?
  1095. (setq originally-looking-at-lone-string (looking-at "\"[^\"]*\"[ \t]*$"))
  1096. ;; Are we in a multi-line parenthesis expression?
  1097. (if (or (and (> (eif-in-paren-expression) 0)
  1098. (> (setq indent (eif-indent-multi-line)) -1))
  1099. (setq indent (eif-manifest-array-indent)))
  1100. ;; Multi-line parenthesis expression.
  1101. ;; Move string continuation lines as per configuration.
  1102. (if (looking-at "%")
  1103. (setq indent (+ indent (eif-string-continuation-indent-m))))
  1104. ;; Else Find the first preceding line with non-comment source on it
  1105. ;; that is not a continuation line of a multi-line parenthesized
  1106. ;; expression (and isn't a preprocessor line :-).
  1107. ;; Record whether this line begins with an operator. We assume
  1108. ;; that the line is a continuation line if it begins with an operator
  1109. (beginning-of-line)
  1110. (setq continuation (looking-at eif-operator-regexp))
  1111. ;; Record whether the line being indented begins with an "<id> :"
  1112. ;; This is used in indenting assertion tag expressions.
  1113. (setq id-colon (looking-at "[ \t]*[a-zA-Z0-9_]+[ \t]*:"))
  1114. (forward-line -1)
  1115. (beginning-of-line)
  1116. (while (and (looking-at eif-non-source-line)
  1117. (not (= (point) 1)))
  1118. (forward-line -1)
  1119. (beginning-of-line))
  1120. (if (eif-line-contains-close-paren)
  1121. (backward-sexp))
  1122. (eif-skip-leading-whitespace)
  1123. (cond ((and (= (point) 1)
  1124. originally-looking-at-comment
  1125. (setq indent (eif-class-level-comment-indent-m))))
  1126. ;; 'eif-is-keyword-regexp' case must precede
  1127. ;; '(not eif-all-keywords-regexp)' case since "is" is not
  1128. ;; part of 'eif-all-keywords-regexp'
  1129. ((or (looking-at eif-is-keyword-regexp)
  1130. (looking-at eif-multiline-routine-is-keyword-regexp)
  1131. (looking-at eif-obsolete-keyword))
  1132. (if originally-looking-at-comment
  1133. ;; Then the line we are trying to indent is a comment
  1134. (setq indent (eif-feature-level-comment-indent-m))
  1135. ;; Else the line being indented is not a comment
  1136. (setq indent (eif-feature-level-kw-indent-m))))
  1137. ;; Feature indentation keyword or class-level `create'.
  1138. ((or (looking-at eif-feature-indentation-keywords-regexp)
  1139. (and (looking-at eif-create-keyword-regexp)
  1140. (not (save-excursion
  1141. (eif-find-beginning-of-feature)))))
  1142. (setq indent (eif-feature-level-indent-m)))
  1143. ((looking-at eif-create-keyword-regexp)
  1144. (setq indent (eif-current-line-indent)))
  1145. ((and (looking-at eif-indentation-keywords-regexp)
  1146. (not (looking-at eif-once-non-indent-regexp)))
  1147. (if (looking-at eif-end-on-current-line)
  1148. (setq indent (eif-current-line-indent))
  1149. (setq indent
  1150. (+ (eif-current-line-indent) eif-indent-increment))))
  1151. ((looking-at eif-solitary-then-keyword)
  1152. (setq indent (- (+ (eif-current-line-indent) eif-indent-increment)
  1153. (eif-then-indent-m))))
  1154. ((looking-at eif-then-keyword)
  1155. (setq indent (eif-current-line-indent)))
  1156. ((looking-at (concat eif-end-keyword eif-non-id-char-regexp))
  1157. (if (= (setq indent (eif-current-line-indent))
  1158. (eif-feature-level-kw-indent-m))
  1159. (setq indent (eif-feature-level-indent-m))
  1160. (eif-matching-line)
  1161. (if (string-match eif-check-keyword eif-matching-kw-for-end)
  1162. (setq indent (- indent (eif-check-keyword-indent-m))))))
  1163. ((looking-at eif-variable-or-const-regexp)
  1164. ;;Either a variable declaration or a pre or post condition tag
  1165. (if originally-looking-at-comment
  1166. ;; Then the line we are trying to indent is a comment
  1167. (if (= (setq indent (eif-current-line-indent))
  1168. (eif-feature-level-indent-m))
  1169. ;; Then - a feature level comment
  1170. (setq indent (eif-feature-level-comment-indent-m))
  1171. ;; Else - some other kind of comment
  1172. (setq indent (+ indent (eif-body-comment-indent-m))))
  1173. ;; Else the line being indented is not a comment
  1174. (if (setq indent (eif-indent-assertion-continuation id-colon))
  1175. indent
  1176. ;; One of the ways of getting here is when we're
  1177. ;; in a split line in an indexing clause.
  1178. ;; Strings on their own need to be given some
  1179. ;; extra indent.
  1180. (if originally-looking-at-lone-string
  1181. (if (looking-at "[ \t]*\"[^\"]*\"[ \t]*$")
  1182. (setq indent (eif-current-line-indent))
  1183. (setq indent (+ (eif-current-line-indent)
  1184. eif-indent-increment)))
  1185. (setq indent (eif-current-line-indent))))))
  1186. ((setq indent (eif-manifest-array-start))
  1187. indent)
  1188. ;; OK, this is a sanity check, but it kills a minor
  1189. ;; instance of `create', so we need to code the corner
  1190. ;; case. As for minor instance of `once'.
  1191. ((or (not (looking-at eif-all-keywords-regexp))
  1192. (looking-at eif-create-keyword-regexp)
  1193. (looking-at eif-once-non-indent-regexp))
  1194. (if originally-looking-at-comment
  1195. ;; Then the line we are trying to indent is a comment
  1196. (cond ((eif-continuation-line)
  1197. (setq indent
  1198. (+ (- (eif-current-line-indent)
  1199. eif-indent-increment)
  1200. (eif-body-comment-indent-m))))
  1201. ;; preceding line is at eif-feature-level-indent -
  1202. ;; assume that the preceding line is a parent
  1203. ;; class in an inherit clause
  1204. ((= (eif-current-line-indent)
  1205. (eif-feature-level-indent-m))
  1206. (setq indent
  1207. (+ (eif-inherit-level-kw-indent-m)
  1208. (eif-body-comment-indent-m))))
  1209. (t
  1210. (setq indent
  1211. (+ (eif-current-line-indent)
  1212. (eif-body-comment-indent-m)))))
  1213. ;; Else line being indented is not a comment
  1214. ;; The line the point is on is the one above the line being
  1215. ;; indented
  1216. (beginning-of-line)
  1217. (if (or continuation (looking-at eif-operator-eol-regexp))
  1218. ;; Then the line being indented is a continuation line
  1219. (if (eif-continuation-line)
  1220. ;; The line preceding the line being indented is
  1221. ;; also a continuation line. Indent to the current
  1222. ;; line indentation.
  1223. (setq indent (eif-current-line-indent))
  1224. ;; Else The line preceding the line being indented is
  1225. ;; not a continuation line. Indent an extra
  1226. ;; eif-continuation-indent
  1227. (setq indent (+ (eif-current-line-indent)
  1228. (eif-continuation-indent-m))))
  1229. ;; Else the line being indented is not a continuation line.
  1230. (if (eif-continuation-line)
  1231. (if id-colon
  1232. ;; Then the line preceding the one being indented
  1233. ;; is an assertion continuation. Indent the current
  1234. ;; line to the same level as the preceding assertion
  1235. ;; tag.
  1236. (setq indent (eif-indent-assertion-tag))
  1237. ;; Then the line preceding the one being indented is
  1238. ;; a continuation line. Un-indent by an
  1239. ;; eif-continuation-indent.
  1240. (setq indent (- (eif-current-line-indent)
  1241. eif-indent-increment)))
  1242. ;; Else the line preceding the line being indented is
  1243. ;; also not a continuation line.
  1244. (if (and (looking-at "[ \t]*\"[^\"]*\"[ \t]*$")
  1245. (not originally-looking-at-lone-string))
  1246. (setq indent (- (eif-current-line-indent)
  1247. eif-indent-increment))
  1248. ;; Else use the current indent.
  1249. (setq indent (eif-current-line-indent))))))))))
  1250. indent))
  1251. (defun eif-continuation-line ()
  1252. "Return non-nil if the current line is a continuation line."
  1253. (or (looking-at eif-operator-regexp)
  1254. (save-excursion
  1255. (forward-line -1)
  1256. (beginning-of-line)
  1257. (looking-at eif-operator-eol-regexp))))
  1258. (defun eif-indent-assertion-continuation (id-colon)
  1259. "Generally, are we in line that is a continuation of an assertion?
  1260. More precisely, are we inside a pre or a post condition clause on a
  1261. line that is a continuation of a multi-line assertion beginning with a
  1262. tag? If so, return the indentation of the continuation line. The
  1263. argument ID-COLON is t if the line we are indenting begins with
  1264. \"<id> :\", and nil otherwise."
  1265. (let ((limit (point)))
  1266. (if (save-excursion
  1267. (if (re-search-backward
  1268. (concat eif-feature-level-keywords-regexp "\\|"
  1269. eif-end-keyword-regexp) nil t)
  1270. (if (looking-at "ensure\\|require")
  1271. (setq limit (point)))))
  1272. (save-excursion
  1273. (end-of-line)
  1274. (if (and (not id-colon) (re-search-backward ": *" limit t))
  1275. (progn
  1276. (goto-char (match-end 0))
  1277. (current-column)))))))
  1278. (defun eif-indent-assertion-tag ()
  1279. "Return indentation for part of a multi-line assertion.
  1280. That is, the current line is assumed to be a continuation of a
  1281. multi-line assertion, and we return the required indentation."
  1282. (save-excursion
  1283. (if (re-search-backward "ensure\\|require\\|variant\\|invariant" nil t)
  1284. (+ (eif-current-line-indent) eif-indent-increment)
  1285. ;; This option should not occur
  1286. (error "Could not find assertion tag"))))
  1287. (defun eif-matching-kw (matching-keyword-regexp &optional noerror)
  1288. "Search backwards and return a keyword in MATCHING-KEYWORD-REGEXP.
  1289. Also set the value of variable `eif-matching-indent' to the
  1290. indentation of the keyword found. If an `end' keyword occurs prior to
  1291. finding one of the keywords in MATCHING-KEYWORD-REGEXP and it
  1292. terminates a check clause, set the value of variable
  1293. `eif-matching-indent' to the indentation of the `end' minus the value
  1294. of `eif-check-keyword-indent'."
  1295. (let ((search-regexp (concat "[^a-z0-9A-Z_.]"
  1296. eif-end-keyword
  1297. "[^a-z0-9A-Z_.]\\|[^a-z0-9A-Z_.]"
  1298. matching-keyword-regexp
  1299. "\\|" eif-once-non-indent-regexp))
  1300. (keyword nil))
  1301. (save-excursion
  1302. ;; Search backward for a matching keyword.
  1303. ;; Note that eif-once-non-indent-regexp indicates we haven't
  1304. ;; found a match so should keep going.
  1305. (while (and (eif-re-search-backward search-regexp 1 t)
  1306. (looking-at eif-once-non-indent-regexp)
  1307. (not (= (point) 1))))
  1308. (if (looking-at search-regexp)
  1309. ;; Then - a keyword was found
  1310. (progn
  1311. (setq keyword
  1312. (buffer-substring (match-beginning 0) (match-end 0)))
  1313. (if (and (looking-at eif-end-keyword-regexp)
  1314. (eif-matching-line)
  1315. (string-match eif-check-keyword eif-matching-kw-for-end))
  1316. ;; Then
  1317. (setq eif-matching-indent (- (eif-current-line-indent)
  1318. (eif-check-keyword-indent-m)))
  1319. ;; Else
  1320. (setq eif-matching-indent (eif-current-line-indent))))
  1321. ;; Else no keyword was found. I think this is an error
  1322. (setq eif-matching-indent 0)
  1323. (if noerror
  1324. nil
  1325. (message "No matching indent keyword was found")))
  1326. keyword)))
  1327. (defun eif-line-contains-close-paren ()
  1328. "Return t if the current line contains a close paren, nil otherwise.
  1329. If a close paren is found, the point is placed immediately after the
  1330. last close paren on the line. If no paren is found, the point is
  1331. placed at the beginning of the line."
  1332. (let ((search-min 0))
  1333. (beginning-of-line)
  1334. (setq search-min (point))
  1335. (end-of-line)
  1336. (if (search-backward ")" search-min t)
  1337. ;; Then
  1338. (progn
  1339. (forward-char 1)
  1340. t)
  1341. ;; Else
  1342. (beginning-of-line)
  1343. nil)))
  1344. ;; Not Currently Used
  1345. ;;(defun eif-quoted-string-on-line-p ()
  1346. ;; "t if an Eiffel quoted string begins, ends, or is continued
  1347. ;; on current line."
  1348. ;; (save-excursion
  1349. ;; (beginning-of-line)
  1350. ;; ;; Line must either start with optional whitespace immediately followed
  1351. ;; ;; by a '%' or include a '\"'. It must either end with a '%' character
  1352. ;; ;; or must include a second '\"' character.
  1353. ;; (looking-at "^\\([ \t]*%\\|[^\"\n]*\"\\)[^\"\n]*\\(%$\\|\"\\)")))
  1354. (defconst eif-opening-regexp
  1355. "\\<\\(external\\|check\\|deferred\\|do\\|once\\|from\\|if\\|inspect\\|debug\\)\\>"
  1356. "Keywords that open eiffel nesting constructs.")
  1357. ;; OK, this is a horrible hack in all of this to handle "once" as a
  1358. ;; special case because it has been overloaded. The search for the
  1359. ;; opening keyword on the current line is quite reasonably limited to
  1360. ;; the current line. Therefore, the standard hacky way that we avoid
  1361. ;; matching once strings, by making sure they're followed by
  1362. ;; whitespace and a non-double-quote, doesn't work here.
  1363. (defconst eif-non-opening-regexp
  1364. "\\<once\\s-+\""
  1365. "Pattern matching exclusions from `eif-opening-regexp'.")
  1366. (defconst eif-closing-regexp "\\<end\\>"
  1367. "Keywords that close eiffel nesting constructs.")
  1368. (defconst eif-do-regexp "^[[:space:]]*\\(do\\|once\\|external\\|attribute\\)\\>"
  1369. "Keyword that opens eiffel routine body.")
  1370. (defconst eif-opening-or-closing-regexp
  1371. (concat "\\(" eif-opening-regexp "\\|" eif-closing-regexp "\\)")
  1372. "Keywords that open or close eiffel nesting constructs.")
  1373. ;;
  1374. ;; Code to allow indenting whole eiffel blocks
  1375. ;;
  1376. (defun eif-matching-line (&optional return-line-break direction)
  1377. "Return the position of the keyword matching the one on the current line.
  1378. For example, a line containing the keyword `do' is matched by a line
  1379. containing the keyword `end' and a line containing `end' may be
  1380. matched by a number of opening keywords. If the optional parameter
  1381. RETURN-LINE-BREAK is non-nil, the character position returned is the
  1382. beginning (or end) of the line containing the matching keyword instead
  1383. of the position of the keyword itself. If the second optional
  1384. parameter, DIRECTION, is non-nil, the current line is not searched for
  1385. a keyword. Instead, if the value of direction is 'forward, the
  1386. function acts as if an `eif-opening-regexp' is on the current line.
  1387. If the value of direction is 'backward, the function acts as if a
  1388. `eif-closing-regexp' is on the current line. The effect of using the
  1389. direction parameter is to locate either the opening or closing keyword
  1390. of the syntactic construct containing the point."
  1391. (let ((nesting-level 0)
  1392. (search-end 0)
  1393. matching-point opening-keyword match-start match-end
  1394. success start-point)
  1395. (unwind-protect
  1396. (save-excursion
  1397. (setq eif-matching-kw-for-end "");; public variable set by this function
  1398. (setq start-point (point))
  1399. (end-of-line)
  1400. (setq search-end (point))
  1401. (beginning-of-line)
  1402. ;; Set starting state: If direction was specified use it.
  1403. ;; If direction is nil, search for a keyword on the current line
  1404. ;; If the keyword is in eif-opening-regexp, set the search
  1405. ;; direction to 'forward, if the keyword on the current line is `end'
  1406. ;; set the search direction to 'backward.
  1407. (cond ((eq direction 'forward)
  1408. (end-of-line) ;; So we wont see keywords on this line.
  1409. (setq nesting-level 1))
  1410. ((eq direction 'backward)
  1411. (beginning-of-line) ;; So we wont see keywords on this line.
  1412. (setq nesting-level -1))
  1413. ((and (re-search-forward eif-opening-regexp search-end t)
  1414. (eif-not-in-comment-or-quoted-string-p))
  1415. (setq match-start (match-beginning 0))
  1416. (setq match-end (match-end 0))
  1417. (goto-char match-start)
  1418. (if (and (not (looking-at eif-non-opening-regexp))
  1419. (eif-not-in-comment-or-quoted-string-p))
  1420. (setq nesting-level 1))
  1421. (setq opening-keyword
  1422. (cons (buffer-substring match-start match-end)
  1423. opening-keyword))
  1424. (goto-char match-end))
  1425. ((and (progn (beginning-of-line) t)
  1426. (re-search-forward eif-closing-regexp search-end t)
  1427. (eif-not-in-comment-or-quoted-string-p))
  1428. (goto-char (match-beginning 0))
  1429. (if (eif-not-in-comment-or-quoted-string-p)
  1430. (setq nesting-level -1))))
  1431. ;; Perform the search
  1432. (while (not (= nesting-level 0))
  1433. (if (> nesting-level 0)
  1434. ;; Then search forward for the next keyword not in a comment
  1435. (while (and (re-search-forward eif-opening-or-closing-regexp nil 1)
  1436. (goto-char (setq match-start (match-beginning 0)))
  1437. (setq match-end (match-end 0))
  1438. (setq success t)
  1439. (or (looking-at eif-non-opening-regexp)
  1440. (eif-in-comment-or-quoted-string-p)))
  1441. (goto-char match-end)
  1442. (setq success nil))
  1443. ;; Else search backward for the next keyword not in a comment
  1444. (while (and (re-search-backward eif-opening-or-closing-regexp nil 1)
  1445. (goto-char (setq match-start (match-beginning 0)))
  1446. (setq success t)
  1447. (or (looking-at eif-non-opening-regexp)
  1448. (eif-in-comment-or-quoted-string-p)))
  1449. (setq success nil)))
  1450. (cond ((and (not (looking-at eif-non-opening-regexp))
  1451. (looking-at eif-opening-regexp)
  1452. success)
  1453. ;; Found an opening keyword
  1454. (if (> nesting-level 0)
  1455. ;; Then
  1456. (if (looking-at eif-do-regexp)
  1457. ;; Then
  1458. (setq nesting-level -1)
  1459. ;; Else
  1460. (setq opening-keyword
  1461. (cons (buffer-substring match-start
  1462. (match-end 0))
  1463. opening-keyword))
  1464. (goto-char (match-end 0)))
  1465. ;; Else
  1466. (if (= nesting-level -1)
  1467. ;; Then
  1468. (progn
  1469. (setq eif-matching-kw-for-end
  1470. (buffer-substring match-start (match-end 0)))
  1471. (if (looking-at "[ \t\n]+")
  1472. (goto-char (match-end 0))))
  1473. ;; Else
  1474. (if (looking-at eif-do-regexp)
  1475. ;; Then
  1476. (progn
  1477. (goto-char (eif-matching-line nil 'forward))
  1478. (setq nesting-level -1))))
  1479. (setq opening-keyword (cdr opening-keyword))
  1480. (if return-line-break
  1481. (beginning-of-line)))
  1482. (setq nesting-level (1+ nesting-level)))
  1483. ((and (looking-at eif-closing-regexp) success)
  1484. ;; Found an opening keyword
  1485. (if (> nesting-level 0)
  1486. ;; Then
  1487. (progn
  1488. (setq opening-keyword (cdr opening-keyword))
  1489. (if return-line-break
  1490. (end-of-line))
  1491. (goto-char (match-end 0)))
  1492. ;; Else
  1493. (setq opening-keyword
  1494. (cons (buffer-substring (match-beginning 0)
  1495. (match-end 0))
  1496. opening-keyword)))
  1497. (setq nesting-level (1- nesting-level)))
  1498. (t (message (concat "Could not find match"
  1499. (if (car opening-keyword)
  1500. (concat " for: "
  1501. (car opening-keyword)))))
  1502. (goto-char start-point)
  1503. (setq nesting-level 0))))
  1504. (setq matching-point (point))))
  1505. (set-mark matching-point)))
  1506. ;; ENHANCEME: Make this function correctly indent more than just routine
  1507. ;; bodies and their sub-constructs. At the least it should
  1508. ;; handle whole routines also.
  1509. (defun eif-indent-construct ()
  1510. "Indent an entire eiffel syntactic construct.
  1511. It is assumed that the point is within a nesting construct ('do',
  1512. `once', 'check', 'if', 'from', or 'inspect'). The whole construct is
  1513. indented up to the matching end. If the point is not within such a
  1514. construct, then only that line is indented"
  1515. (interactive)
  1516. (let ((end-point 0))
  1517. (save-excursion
  1518. (end-of-line)
  1519. (if (not (= (point) (point-max))) (forward-char 1))
  1520. (goto-char (eif-matching-line t 'backward))
  1521. (setq end-point (eif-matching-line t 'forward))
  1522. (while (< (point) end-point)
  1523. (eif-indent-line)
  1524. (forward-line 1)
  1525. (beginning-of-line)))))
  1526. (defun eif-indent-region (&optional start end)
  1527. "Indent the lines in the current region.
  1528. The region may be specified using optional arguments START and END."
  1529. (interactive)
  1530. (let ((start-point (or start (region-beginning)))
  1531. (end-point (copy-marker (or end (region-end)))))
  1532. (save-excursion
  1533. (goto-char start-point)
  1534. (cond ((eq major-mode 'eiffel-mode)
  1535. (while (< (point) end-point)
  1536. (if (not (looking-at "[ \t]*$"))
  1537. (eif-indent-line))
  1538. (forward-line 1)
  1539. (beginning-of-line)))
  1540. (t (error "Buffer must be in eiffel mode"))))))
  1541. (defadvice isearch-yank-word (around eif-isearch-yank-word activate)
  1542. "isearch-yank-word, with the underscore not being a letter"
  1543. (interactive)
  1544. (modify-syntax-entry ?_ "_ ")
  1545. ad-do-it
  1546. (modify-syntax-entry ?_ "w "))
  1547. (defadvice isearch-yank-word-or-char (around eif-isearch-yank-word-or-char activate)
  1548. "isearch-yank-word-or-char, with the underscore not being a letter"
  1549. (interactive)
  1550. (modify-syntax-entry ?_ "_ ")
  1551. ad-do-it
  1552. (modify-syntax-entry ?_ "w "))
  1553. (defadvice forward-word (around eif-forward-word activate)
  1554. "forward-word, with the underscore not being a letter"
  1555. (interactive "p")
  1556. (modify-syntax-entry ?_ "_ ")
  1557. ad-do-it
  1558. (modify-syntax-entry ?_ "w "))
  1559. (defadvice backward-word (around eif-backward-word activate)
  1560. "backward-word, with the underscore not being a letter"
  1561. (interactive "p")
  1562. (modify-syntax-entry ?_ "_ ")
  1563. ad-do-it
  1564. (modify-syntax-entry ?_ "w "))
  1565. (defadvice right-word (around eif-forward-word activate)
  1566. "right-word, with the underscore not being a letter"
  1567. (interactive "p")
  1568. (modify-syntax-entry ?_ "_ ")
  1569. ad-do-it
  1570. (modify-syntax-entry ?_ "w "))
  1571. (defadvice left-word (around eif-backward-word activate)
  1572. "left-word, with the underscore not being a letter"
  1573. (interactive "p")
  1574. (modify-syntax-entry ?_ "_ ")
  1575. ad-do-it
  1576. (modify-syntax-entry ?_ "w "))
  1577. (defadvice backward-kill-word (around eif-backward-kill-word activate)
  1578. "backward-kill-word, with the underscore not being a letter"
  1579. (interactive "p")
  1580. (modify-syntax-entry ?_ "_ ")
  1581. ad-do-it
  1582. (modify-syntax-entry ?_ "w "))
  1583. (defadvice kill-word (around eif-kill-word activate)
  1584. "kill-word, with the underscore not being a letter"
  1585. (interactive "p")
  1586. (modify-syntax-entry ?_ "_ ")
  1587. ad-do-it
  1588. (modify-syntax-entry ?_ "w "))
  1589. (defun eif-local-indent (amount)
  1590. "Set the value of `eif-indent-increment' to AMOUNT buffer-locally."
  1591. (interactive "NNumber of spaces for eif-indent-increment: ")
  1592. (make-local-variable 'eif-indent-increment)
  1593. (setq eif-indent-increment amount))
  1594. ;; ----------------------------------------------------------------------
  1595. ;; This next portion of the file is derived from "eiffel.el"
  1596. ;; Copyright (C) 1989, 1990 Free Software Foundation, Inc. and Bob Weiner
  1597. ;; Available for use and distribution under the same terms as GNU Emacs.
  1598. ;; ----------------------------------------------------------------------
  1599. (defvar eiffel-mode-map nil
  1600. "Keymap for Eiffel mode.")
  1601. (if eiffel-mode-map
  1602. nil
  1603. (let ((map (make-sparse-keymap)))
  1604. (define-key map [(control j)] 'newline-and-indent)
  1605. (define-key map [(return)] 'reindent-then-newline-and-indent)
  1606. (define-key map [(meta control q)] 'eif-indent-construct)
  1607. (define-key map [(meta \')] 'eif-feature-quote)
  1608. (define-key map [(meta q)] 'eif-fill-paragraph)
  1609. (define-key map [(meta control a)] 'eif-beginning-of-feature)
  1610. (define-key map [(meta control e)] 'eif-end-of-feature)
  1611. (define-key map [(control x) ?n ?d] 'eif-narrow-to-feature)
  1612. (define-key map [(control c) ?c] 'eif-class)
  1613. (define-key map [(control c) ?f] 'eif-function)
  1614. (define-key map [(control c) ?p] 'eif-procedure)
  1615. (define-key map [(control c) ?a] 'eif-attribute)
  1616. (define-key map [(control c) ?i] 'eif-if)
  1617. (define-key map [(control c) ?l] 'eif-loop)
  1618. (define-key map [(control c) ?s] 'eif-set)
  1619. (define-key map [(control c) ?n] 'eif-inspect)
  1620. (define-key map [(control c) ?w] 'eif-when)
  1621. (define-key map [(control c) ?e] 'eif-elseif)
  1622. (define-key map [(meta control a)] 'eif-beginning-of-feature)
  1623. (define-key map [(meta control e)] 'eif-end-of-feature)
  1624. (define-key map [(meta control h)] 'eif-mark-feature)
  1625. (setq eiffel-mode-map map)))
  1626. (defvar eiffel-mode-syntax-table nil
  1627. "Syntax table in use in Eiffel-mode buffers.")
  1628. (if eiffel-mode-syntax-table
  1629. nil
  1630. (let ((table (make-syntax-table))
  1631. (i 0))
  1632. (while (< i ?0)
  1633. (modify-syntax-entry i "_ " table)
  1634. (setq i (1+ i)))
  1635. (setq i (1+ ?9))
  1636. (while (< i ?A)
  1637. (modify-syntax-entry i "_ " table)
  1638. (setq i (1+ i)))
  1639. (setq i (1+ ?Z))
  1640. (while (< i ?a)
  1641. (modify-syntax-entry i "_ " table)
  1642. (setq i (1+ i)))
  1643. (setq i (1+ ?z))
  1644. (while (< i 128)
  1645. (modify-syntax-entry i "_ " table)
  1646. (setq i (1+ i)))
  1647. (modify-syntax-entry ? " " table)
  1648. (modify-syntax-entry ?- ". 12" table)
  1649. (modify-syntax-entry ?_ "w " table)
  1650. (modify-syntax-entry ?\t " " table)
  1651. (modify-syntax-entry ?\n "> " table)
  1652. (modify-syntax-entry ?\f "> " table)
  1653. (modify-syntax-entry ?\" "\" " table)
  1654. (modify-syntax-entry ?\\ "." table)
  1655. (modify-syntax-entry ?\( "() " table)
  1656. (modify-syntax-entry ?\) ")( " table)
  1657. (modify-syntax-entry ?\[ "(] " table)
  1658. (modify-syntax-entry ?\] ")[ " table)
  1659. (modify-syntax-entry ?\{ "(} " table)
  1660. (modify-syntax-entry ?\} "){ " table)
  1661. (modify-syntax-entry ?' "\"" table)
  1662. (modify-syntax-entry ?` "." table)
  1663. (modify-syntax-entry ?/ "." table)
  1664. (modify-syntax-entry ?* "." table)
  1665. (modify-syntax-entry ?+ "." table)
  1666. (modify-syntax-entry ?= "." table)
  1667. (modify-syntax-entry ?% "\\" table)
  1668. (modify-syntax-entry ?< "." table)
  1669. (modify-syntax-entry ?> "." table)
  1670. (modify-syntax-entry ?& "." table)
  1671. (modify-syntax-entry ?| "." table)
  1672. (modify-syntax-entry ?\; "." table)
  1673. (modify-syntax-entry ?: "." table)
  1674. (modify-syntax-entry ?! "." table)
  1675. (modify-syntax-entry ?. "." table)
  1676. (modify-syntax-entry ?, "." table)
  1677. (setq eiffel-mode-syntax-table table)))
  1678. (defun eif-add-menu ()
  1679. "Add the \"Eiffel\" menu to the menu bar."
  1680. (easy-menu-define
  1681. eiffel-mode-menu
  1682. eiffel-mode-map
  1683. "Menu for eiffel-mode."
  1684. (append (list "LibertyEiffel")
  1685. (if eif-use-gnu-eiffel
  1686. (list
  1687. ["Compile..." eif-compile t]
  1688. ["Compiler Options..." eif-set-compile-options t]
  1689. ["Next Compile Error..." next-error t]
  1690. ["Run..." eif-run t]
  1691. ["Debug..." eif-debug t]
  1692. ["Short..." eif-short t]
  1693. ["----------" nil nil]))
  1694. (list
  1695. ["Indent Construct" eif-indent-construct t]
  1696. (list "Insert"
  1697. ["Class" eif-class t]
  1698. ["Command" eif-procedure t]
  1699. ["Query" eif-function t]
  1700. ["Attribute" eif-attribute t]
  1701. ["Attribute setter" eif-set t]
  1702. ["If" eif-if t]
  1703. ["Loop" eif-loop t]
  1704. ["Inspect" eif-inspect t]
  1705. ["When" eif-when t]
  1706. ["Elseif" eif-elseif t])
  1707. ["----------" nil nil]
  1708. (list "Imenu"
  1709. ["By position" eif-imenu-add-menubar-by-position t]
  1710. ["By name" eif-imenu-add-menubar-by-name t])
  1711. (list "Comments"
  1712. ["Feature Quote" eif-feature-quote (eif-in-comment-p)]
  1713. ["Fill " eif-fill-paragraph (eif-near-comment-p)])
  1714. ["----------" nil nil]
  1715. ["Customize" eif-customize t])))
  1716. (easy-menu-add eiffel-mode-menu))
  1717. ;;;###autoload
  1718. (add-to-list 'auto-mode-alist '("\\.e\\'" . eiffel-mode))
  1719. (add-to-list 'auto-mode-alist '("\\.se\\'" . eiffel-mode))
  1720. (defun eiffel-mode ()
  1721. "Major mode for editing Eiffel programs.
  1722. \\[indent-for-tab-command] indents the current Eiffel line correctly and
  1723. \\[reindent-then-newline-and-indent] causes the current and next line to be
  1724. properly indented.
  1725. Key definitions:
  1726. \\{eiffel-mode-map}
  1727. If variable `eif-use-gnu-eiffel' is non-nil (default t) then support
  1728. for using GNU SmartEiffel is enabled. Run \\[eif-customize] to see
  1729. compilation and indentation variables that can be customized."
  1730. (interactive)
  1731. (kill-all-local-variables)
  1732. (setq major-mode 'eiffel-mode)
  1733. (setq mode-name "Eiffel")
  1734. (if eif-use-gnu-eiffel
  1735. (progn
  1736. (define-key eiffel-mode-map "\C-c\C-c" 'eif-compile)
  1737. (define-key eiffel-mode-map "\C-c\C-o" 'eif-set-compile-options)
  1738. (define-key eiffel-mode-map "\C-c\C-r" 'eif-run)
  1739. (define-key eiffel-mode-map "\C-c\C-d" 'eif-debug)
  1740. (define-key eiffel-mode-map "\C-c\C-s" 'eif-short)
  1741. (define-key eiffel-mode-map "\C-c\C-f" 'eif-find-file))
  1742. (define-key eiffel-mode-map "\C-c\C-c" nil)
  1743. (define-key eiffel-mode-map "\C-c\C-o" nil)
  1744. (define-key eiffel-mode-map "\C-c\C-r" nil)
  1745. (define-key eiffel-mode-map "\C-c\C-s" nil))
  1746. (use-local-map eiffel-mode-map)
  1747. (eif-add-menu)
  1748. (set-syntax-table eiffel-mode-syntax-table)
  1749. ;; Make local variables.
  1750. (make-local-variable 'paragraph-start)
  1751. (make-local-variable 'paragraph-separate)
  1752. (make-local-variable 'paragraph-ignore-fill-prefix)
  1753. (make-local-variable 'require-final-newline)
  1754. (make-local-variable 'parse-sexp-ignore-comments)
  1755. (make-local-variable 'indent-line-function)
  1756. (make-local-variable 'indent-region-function)
  1757. (make-local-variable 'comment-start)
  1758. (make-local-variable 'comment-end)
  1759. (make-local-variable 'comment-column)
  1760. (make-local-variable 'comment-start-skip)
  1761. (make-local-variable 'imenu-create-index-function)
  1762. ;; Now set their values.
  1763. (setq paragraph-start (concat "^$\\|" page-delimiter)
  1764. paragraph-separate "[ \t ]*$"
  1765. paragraph-ignore-fill-prefix t
  1766. require-final-newline t
  1767. parse-sexp-ignore-comments t
  1768. indent-line-function 'eif-indent-line
  1769. indent-region-function 'eif-indent-region
  1770. comment-start "-- "
  1771. comment-end ""
  1772. comment-column 32
  1773. comment-start-skip eiffel-comment-start-skip
  1774. font-lock-multiline t)
  1775. (set (make-local-variable 'font-lock-defaults) #'(eiffel-font-lock-defaults t))
  1776. (if eif-set-tab-width-flag
  1777. (setq tab-width eif-indent-increment))
  1778. (setq auto-fill-function 'eif-auto-fill)
  1779. (run-hooks 'eiffel-mode-hook))
  1780. (defconst eif-prefeature-regexp
  1781. (concat "\\(" eif-non-source-line "\\|\n\\)*" "[ \t]*")
  1782. "Regexp matching whitespace-equivalent content, possibly before a feature.")
  1783. (defun eif-find-end-of-feature ()
  1784. "Find the `end' of the current feature definition.
  1785. Assumes point is at the beginning of the feature, not in a comment or
  1786. quoted string."
  1787. (let (ret)
  1788. (cond ((looking-at (concat eif-prefeature-regexp
  1789. eif-routine-begin-regexp))
  1790. ;; At the start of a routine, find matching end.
  1791. (and (eif-re-search-forward eif-do-regexp nil t)
  1792. (goto-char (match-beginning 0))
  1793. (goto-char (setq ret (eif-matching-line)))))
  1794. ((looking-at (concat eif-prefeature-regexp
  1795. eif-probably-feature-regexp))
  1796. ;; Not a routine, find end of attribute or constant.
  1797. (goto-char (setq ret (match-end 0)))))
  1798. ret))
  1799. ;; OK, this works well, but it doesn't work for the following cases:
  1800. ;; * In the middle of the feature regexp that need to be matched.
  1801. ;; However, it doesn't need to since eif-beginning-of-feature adds
  1802. ;; some smarts around it...
  1803. (defun eif-find-beginning-of-feature ()
  1804. "Find the beginning of the most recent feature definition.
  1805. This will always move backward, if possible."
  1806. (interactive)
  1807. (let ((start (point))
  1808. candidate routine-begin)
  1809. (if (eif-re-search-backward (concat "\\s-" eif-probably-feature-regexp)
  1810. nil t)
  1811. (progn
  1812. (forward-char) ;; Skip the whitespace character matched above.
  1813. (if (looking-at (regexp-opt eiffel-keywords-feature))
  1814. (eif-find-beginning-of-feature)
  1815. (if (not (or (looking-at (concat
  1816. "\\(" eif-attribute-regexp
  1817. "\\|" eif-constant-regexp "\\)"))))
  1818. ;; This is a routine. Done.
  1819. (point)
  1820. ;; Variable/attribute or constant declaration matched.
  1821. ;; Now we go back and find the previous routine start, the
  1822. ;; following end, and see if the current position
  1823. ;; (candidate) is between. If it is, then candidate is a
  1824. ;; variable or constant declaration within a routine, so
  1825. ;; we're interested in the routine start. If it isn't,
  1826. ;; then it must be a class attribute or constant, so it is
  1827. ;; what we're looking for.
  1828. (setq candidate (point))
  1829. (goto-char start)
  1830. (if (eif-re-search-backward
  1831. (concat "\\s-" eif-routine-begin-regexp) nil t)
  1832. (progn
  1833. (forward-char)
  1834. (setq routine-begin (point))
  1835. (eif-find-end-of-feature)
  1836. (if (and (< routine-begin candidate)
  1837. (< candidate (point)))
  1838. (goto-char routine-begin)
  1839. (goto-char candidate)))
  1840. (goto-char candidate))))))))
  1841. (defun eif-beginning-of-feature (&optional arg)
  1842. "Move backward to next feature beginning.
  1843. With ARG, do it that many times. Negative arg -N
  1844. means move forward to Nth following beginning of feature.
  1845. Returns t unless search stops due to beginning or end of buffer."
  1846. (interactive "p")
  1847. (or arg
  1848. (setq arg 1))
  1849. (let ((start (point))
  1850. (success t))
  1851. (cond ((> arg 0)
  1852. ;; Going backward.
  1853. ;; We have to move forward to make sure we find any feature
  1854. ;; that we might be in the middle of the beginning of. How
  1855. ;; far? How about this far?
  1856. (eif-re-search-forward eif-probably-feature-regexp nil 'move)
  1857. ;; Change arg towards zero as we search, failing if we hit
  1858. ;; edge of buffer.
  1859. (while (and (> arg 0)
  1860. (or (eif-find-beginning-of-feature)
  1861. (setq success nil)))
  1862. ;; If we've gone backwards from the original start, then
  1863. ;; this counts.
  1864. (if (< (point) start)
  1865. (setq arg (1- arg))))
  1866. (or success
  1867. (goto-char (point-min))))
  1868. ((< arg 0)
  1869. ;; Going forward.
  1870. ;; Similar to above, let's go back to the beginning of the
  1871. ;; current feature, and then skip over features and find
  1872. ;; the beginning of the next repeatedly.
  1873. (eif-find-beginning-of-feature)
  1874. (while (and (< arg 0)
  1875. (or (not (eobp)) (setq success nil)))
  1876. (eif-find-end-of-feature)
  1877. (if (eif-re-search-forward eif-probably-feature-regexp
  1878. nil 'move)
  1879. (progn
  1880. (goto-char (match-beginning 0))
  1881. (if (> (point) start)
  1882. (setq arg (1+ arg))))))))
  1883. success))
  1884. (defun eif-end-of-feature (&optional arg)
  1885. "Move forward to end of feature.
  1886. With argument, do it that many times. Negative argument means move
  1887. back ARG preceding ends of features."
  1888. (interactive "p")
  1889. ;; Default is to find the first feature's end.
  1890. ;; Huh? Even if they specify 0? - martin@meltin.net
  1891. ;; Hmmm, it is what end-of-defun does...
  1892. (if (or (null arg)
  1893. (= arg 0))
  1894. (setq arg 1))
  1895. ;; This is a bad way of trying to get into position. Happily, it
  1896. ;; seems to work. Hmmm, not sure if the comment skip is needed.
  1897. (if (eif-in-comment-p)
  1898. (end-of-line))
  1899. (cond ((let ((curr (point)))
  1900. (save-excursion
  1901. (and (eif-beginning-of-feature)
  1902. (eif-find-end-of-feature)
  1903. (forward-line)
  1904. (or (< curr (point))
  1905. (and (< arg 0)
  1906. (= curr (point)))))))
  1907. ;; Within a feature. Go to its beginning.
  1908. (eif-beginning-of-feature))
  1909. ((eif-peeking-backwards-at (concat "\\s-"
  1910. eif-probably-feature-regexp))
  1911. ;; Sitting at beginning of feature. Don't move!
  1912. t)
  1913. (t
  1914. ;; Not within a feature or at beginning, go to beginning of
  1915. ;; next feature.
  1916. (eif-beginning-of-feature -1)))
  1917. ;; This part is correct.
  1918. (if (eif-beginning-of-feature (+ (if (< arg 0) 0 1) (- arg)))
  1919. (progn
  1920. (eif-find-end-of-feature)
  1921. (forward-line))))
  1922. (defun eif-narrow-to-feature ()
  1923. "Make text outside current feature invisible.
  1924. The feature visible is the one that contains point or follows point."
  1925. (interactive)
  1926. (save-excursion
  1927. (widen)
  1928. (eif-end-of-feature)
  1929. (let ((end (point)))
  1930. (eif-beginning-of-feature)
  1931. (narrow-to-region (point) end))))
  1932. (defun eif-current-line-indent ()
  1933. "Return the indentation of the line containing the point."
  1934. (save-excursion
  1935. (eif-skip-leading-whitespace)
  1936. (current-column)))
  1937. (defun eif-in-quoted-string-p (&optional non-strict-p)
  1938. "Return t if point is in a quoted string.
  1939. Optional argument NON-STRICT-P if true causes the function to return
  1940. true even if the point is located in leading white space on a
  1941. continuation line. Normally leading white space is not considered part
  1942. of the string."
  1943. (let ((initial-regexp "^[ \t]*%\\|[^%]U?\"\\|%[ \t]*$")
  1944. (search-limit (point))
  1945. (count 0))
  1946. (save-excursion
  1947. ;; Line must either start with optional whitespace immediately followed
  1948. ;; by a '%' or include a '\"' before the search-limit.
  1949. (beginning-of-line)
  1950. (while (re-search-forward initial-regexp search-limit t)
  1951. (setq count (1+ count))
  1952. (if (= count 1) (setq search-limit (1+ search-limit))))
  1953. ;; If the number of quotes (including continuation line markers)
  1954. ;; is odd, then we are inside of a string. Also if non-strict-p
  1955. ;; and we are in the leading white space of a continuation line,
  1956. ;; then we are in a quote.
  1957. (or (= (% count 2) 1)
  1958. (progn
  1959. (beginning-of-line)
  1960. (and non-strict-p
  1961. (looking-at "^[ \t]*%")))))))
  1962. ;; ----------------------------------------------------------------------
  1963. ;; End of portion derived from "eiffel.el"
  1964. ;; ----------------------------------------------------------------------
  1965. (defun eif-comment-prefix ()
  1966. "Return the prefix starting a comment that begins a line.
  1967. Comments that are not the only thing on a line return nil as their prefix."
  1968. (save-excursion
  1969. (end-of-line)
  1970. (let ((limit (point)) len
  1971. (in-string (eif-in-quoted-string-p)))
  1972. (beginning-of-line)
  1973. (cond ((re-search-forward "^[ \t]*--|?[ \t]*" limit t)
  1974. (buffer-substring (match-beginning 0) (match-end 0)))
  1975. ;; Handle string-literal continuation lines
  1976. (in-string
  1977. (end-of-line)
  1978. (re-search-backward "^[ \t]*%\\|[^%]\"" nil t)
  1979. (re-search-forward "%\\|\"" nil t)
  1980. (setq len (1- (current-column)))
  1981. (concat (make-string len ? ) "%"))))))
  1982. (defun eif-auto-fill ()
  1983. "Auto-fill an Eiffel comment."
  1984. (let ((fill-prefix (eif-comment-prefix))
  1985. (pm (point-marker)))
  1986. (if (and (> (current-column) fill-column)
  1987. fill-prefix)
  1988. (if (string-match "^[ \t]*%" fill-prefix)
  1989. (progn
  1990. (backward-char 1)
  1991. (re-search-backward "[^][a-zA-Z0-9]" nil t)
  1992. (forward-char 1)
  1993. (insert "%\n")
  1994. (insert fill-prefix)
  1995. (goto-char pm))
  1996. ;; (do-auto-fill)
  1997. (backward-char 1)
  1998. (re-search-backward "\\s-" nil t)
  1999. (forward-char 1)
  2000. (insert "\n")
  2001. (insert fill-prefix)
  2002. (goto-char pm)))))
  2003. (defun eif-fill-paragraph ()
  2004. "Textually fills Eiffel comments ala \\[fill-paragraph]."
  2005. (interactive)
  2006. (save-excursion
  2007. (let ((current-point (point))
  2008. (fill-prefix (eif-comment-prefix))
  2009. last-point para-begin para-end)
  2010. (if fill-prefix
  2011. (progn
  2012. (setq last-point (point))
  2013. (forward-line -1)
  2014. (end-of-line)
  2015. (while (and (not (= (point) last-point))
  2016. (eif-comment-prefix))
  2017. (setq last-point (point))
  2018. (forward-line -1)
  2019. (end-of-line))
  2020. (if (= (point) last-point)
  2021. (setq para-begin (save-excursion (beginning-of-line) (point)))
  2022. (setq para-begin (1+ (point))))
  2023. (goto-char current-point)
  2024. (setq last-point (point))
  2025. (forward-line 1)
  2026. (end-of-line)
  2027. (while (and (not (= (point) last-point))
  2028. (eif-comment-prefix))
  2029. (setq last-point (point))
  2030. (forward-line 1)
  2031. (end-of-line))
  2032. (if (= (point) last-point)
  2033. (setq para-end (point))
  2034. (beginning-of-line)
  2035. (setq para-end (point)))
  2036. ;; Avert eyes now - gross hack follows... how big can an
  2037. ;; Eiffel comment be anyway? :-)
  2038. (let ((orig-region (and (<= (- para-end para-begin)
  2039. eif-fill-max-save)
  2040. (buffer-substring para-begin para-end)))
  2041. (orig-state (buffer-modified-p))
  2042. (ret (fill-region para-begin para-end)))
  2043. (and orig-region
  2044. (<= para-end (point-max))
  2045. (string-equal
  2046. orig-region (buffer-substring para-begin para-end))
  2047. (set-buffer-modified-p orig-state))
  2048. ret))))))
  2049. (defun eif-indent-line (&optional whole-exp)
  2050. "Indent the current line as Eiffel code.
  2051. With optional argument WHOLE-EXP, indent any additional lines of the
  2052. same clause rigidly along with this one (not implemented yet)."
  2053. (interactive "p")
  2054. (save-excursion
  2055. (beginning-of-line)
  2056. (skip-chars-forward " \t")
  2057. (let ((indent (eif-calc-indent)))
  2058. (if (not (= indent (current-column)))
  2059. (progn
  2060. (delete-horizontal-space)
  2061. (indent-to indent)))))
  2062. (skip-chars-forward " \t"))
  2063. (defun eif-move-to-prev-non-blank ()
  2064. "Move point to previous line excluding blank lines.
  2065. Return t if successful, nil if not."
  2066. (beginning-of-line)
  2067. (re-search-backward "^[ \t]*[^ \t\n]" nil t))
  2068. (defvar eif-last-feature-level-indent -1)
  2069. (defvar eif-feature-level-indent-regexp nil)
  2070. (defun eif-in-paren-expression ()
  2071. "Determine if we are inside of a parenthesized expression."
  2072. (interactive)
  2073. (let ((paren-count 0) (limit 0))
  2074. (save-excursion
  2075. (if (= eif-last-feature-level-indent (eif-feature-level-indent-m))
  2076. (setq limit
  2077. (re-search-backward eif-feature-level-indent-regexp nil t))
  2078. (setq eif-last-feature-level-indent (eif-feature-level-indent-m))
  2079. (setq eif-feature-level-indent-regexp
  2080. (concat "^" (make-string eif-last-feature-level-indent ? )
  2081. "[^ \t\n]"))
  2082. (setq limit
  2083. (or (re-search-backward eif-feature-level-indent-regexp nil t)
  2084. 0))))
  2085. (save-excursion
  2086. (while (re-search-backward "[][()]" limit t)
  2087. (if (looking-at "[[(]")
  2088. (setq paren-count (1+ paren-count))
  2089. (setq paren-count (1- paren-count)))))
  2090. paren-count))
  2091. (defun eif-manifest-array-common ()
  2092. "Common code for handling indentation/presence of Eiffel manifest arrays."
  2093. (let ((paren-count 0))
  2094. (if (= eif-last-feature-level-indent (eif-feature-level-indent-m))
  2095. nil
  2096. (setq eif-last-feature-level-indent (eif-feature-level-indent-m))
  2097. (setq eif-feature-level-indent-regexp
  2098. (concat "^" (make-string eif-last-feature-level-indent ? )
  2099. "[^ \t\n]")))
  2100. (while (and (<= paren-count 0) (re-search-backward "<<\\|>>" nil t))
  2101. (if (not (eif-peeking-backwards-at "|\\|@"))
  2102. (if (looking-at "<<")
  2103. (setq paren-count (1+ paren-count))
  2104. (setq paren-count (1- paren-count)))))
  2105. paren-count))
  2106. (defun eif-manifest-array-indent ()
  2107. "Determine if we are inside of a manifest array."
  2108. (interactive)
  2109. (let (indent)
  2110. (save-excursion
  2111. (if (> (eif-manifest-array-common) 0)
  2112. (let ((eol (save-excursion (end-of-line) (point))))
  2113. (setq indent
  2114. (or (and (re-search-forward "[^< \t]" eol t)
  2115. (1- (current-column)))
  2116. (+ (current-column) 2))))))
  2117. indent))
  2118. (defun eif-manifest-array-start ()
  2119. "Determine the indentation of the statement containing a manifest array."
  2120. (interactive)
  2121. (let (indent)
  2122. (save-excursion
  2123. (if (> (eif-manifest-array-common) 0)
  2124. (let ((limit (progn (end-of-line) (point))))
  2125. (beginning-of-line)
  2126. (if (re-search-forward "^[ \t]*<<" limit t)
  2127. (setq indent (- (current-column) 2 eif-indent-increment))
  2128. (re-search-forward "^[ \t]*" limit t)
  2129. (setq indent (current-column))))))
  2130. indent))
  2131. ;; ----------------------------------------------------------------------
  2132. ;; The function below is derived from "eif-mult-fmt.el"
  2133. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  2134. ;; Copyright (C) 1990 Bob Weiner, Motorola Inc.
  2135. ;; Available for use and distribution under the same terms as GNU Emacs.
  2136. ;; ----------------------------------------------------------------------
  2137. (defun eif-indent-multi-line (&optional parse-start)
  2138. "Return indentation for line within parentheses or double quotes.
  2139. That is, we are in a multi-line parenthesised or double-quoted
  2140. expression, and want to know the suggested indentation for the current
  2141. line. If we are not within such an expression then return -1.
  2142. Optional argument PARSE-START is buffer position at which to begin
  2143. parsing, default is to begin at the feature enclosing or preceding
  2144. point."
  2145. (let ((eif-opoint (point))
  2146. (indent-point (progn (beginning-of-line) (point)))
  2147. (eif-ind-val -1)
  2148. (eif-in-str nil)
  2149. (eif-paren-depth 0)
  2150. (retry t)
  2151. state
  2152. ;; setting this to a number inhibits calling hook
  2153. last-sexp containing-sexp)
  2154. (if parse-start
  2155. (goto-char parse-start)
  2156. (eif-beginning-of-feature))
  2157. ;; Find outermost containing sexp
  2158. (while (< (point) indent-point)
  2159. (setq state (parse-partial-sexp (point) indent-point 0)))
  2160. ;; Find innermost containing sexp
  2161. (while (and retry
  2162. state
  2163. (> (setq eif-paren-depth (elt state 0)) 0))
  2164. (setq retry nil)
  2165. (setq last-sexp (elt state 2))
  2166. (setq containing-sexp (elt state 1))
  2167. ;; Position following last unclosed open.
  2168. (goto-char (1+ containing-sexp))
  2169. ;; Is there a complete sexp since then?
  2170. (if (and last-sexp (> last-sexp (point)))
  2171. ;; Yes, but is there a containing sexp after that?
  2172. (let ((peek (parse-partial-sexp last-sexp indent-point 0)))
  2173. (if (setq retry (car (cdr peek))) (setq state peek)))))
  2174. (if retry
  2175. nil
  2176. ;; Innermost containing sexp found
  2177. (goto-char (1+ containing-sexp))
  2178. (if (not last-sexp)
  2179. ;; indent-point immediately follows open paren.
  2180. nil
  2181. ;; Find the start of first element of containing sexp.
  2182. (parse-partial-sexp (point) last-sexp 0 t)
  2183. (cond ((looking-at "\\s(")
  2184. ;; First element of containing sexp is a list.
  2185. ;; Indent under that list.
  2186. )
  2187. ((> (save-excursion (forward-line 1) (point))
  2188. last-sexp)
  2189. ;; This is the first line to start within the containing sexp.
  2190. (backward-prefix-chars))
  2191. (t
  2192. ;; Indent beneath first sexp on same line as last-sexp.
  2193. ;; Again, it's almost certainly a routine call.
  2194. (goto-char last-sexp)
  2195. (beginning-of-line)
  2196. (parse-partial-sexp (point) last-sexp 0 t)
  2197. (backward-prefix-chars))))
  2198. (setq eif-ind-val (current-column)))
  2199. ;; Point is at the point to indent under unless we are inside a string.
  2200. (setq eif-in-str (elt state 3))
  2201. (goto-char eif-opoint)
  2202. (if (not eif-in-str)
  2203. nil
  2204. ;; Inside a string, indent 1 past string start
  2205. (setq eif-paren-depth 1);; To account for being inside string
  2206. (save-excursion
  2207. (if (re-search-backward "\"" nil t)
  2208. (if eif-indent-string-continuations-relatively-flag
  2209. (setq eif-ind-val (1+ (current-column)))
  2210. (setq eif-ind-val (eif-current-line-indent)))
  2211. (goto-char indent-point)
  2212. (if (looking-at "^[ \t]*[^ \t\n]")
  2213. (eif-move-to-prev-non-blank))
  2214. (skip-chars-forward " \t")
  2215. (setq eif-ind-val (current-column)))))
  2216. (if (> eif-paren-depth 0) eif-ind-val -1)))
  2217. ;; ----------------------------------------------------------------------
  2218. ;; imenu support, great for browsing foreign code.
  2219. ;; Originally contributed by Berend de Boer <berend@pobox.com>.
  2220. ;; ----------------------------------------------------------------------
  2221. (defun eif-imenu-add-menubar-by-position ()
  2222. "Add menu of features of a class, sorted in order of occurence."
  2223. (interactive)
  2224. (setq imenu-create-index-function 'eif-imenu-create-index-by-position)
  2225. (imenu-add-to-menubar "Eiffel features")
  2226. )
  2227. (defun eif-imenu-add-menubar-by-name ()
  2228. "Add menu of features of a class, sorted by name."
  2229. (interactive)
  2230. (setq imenu-create-index-function 'eif-imenu-create-index-by-name)
  2231. (imenu-add-to-menubar "Eiffel names"))
  2232. (defun eif-imenu-create-index-by-position ()
  2233. "Generate index of features of a class, sorted in order of occurence."
  2234. (eif-imenu-create-index 0))
  2235. (defun eif-imenu-create-index-by-name ()
  2236. "Generate index of features of a class, sorted by name."
  2237. (eif-imenu-create-index 1))
  2238. (defun eif-imenu-create-index (sort-method)
  2239. "Generate an index of all features of a class.
  2240. Sort by position if sort-method is 0. Sort by name if sort-method is 1."
  2241. (let (menu prevpos)
  2242. (imenu-progress-message prevpos 0 t)
  2243. ;; scan for features
  2244. (goto-char (point-max))
  2245. (while (eif-find-beginning-of-feature)
  2246. (imenu-progress-message prevpos nil t)
  2247. (if (looking-at "\\(\\sw\\|\\s_\\)+")
  2248. (add-to-list 'menu (cons (buffer-substring-no-properties
  2249. (match-beginning 0)
  2250. (match-end 0)) (point)))))
  2251. (imenu-progress-message prevpos 100)
  2252. ;; sort in increasing buffer position order or by name
  2253. (if (= sort-method 0)
  2254. (sort menu (function (lambda (a b) (< (cdr a) (cdr b)))))
  2255. (sort menu (function (lambda (a b) (string< (car a) (car b))))))))
  2256. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2257. ;; C. Adrian: added good old features for code templating
  2258. (defun eif-class ()
  2259. "Insert a 'class' template."
  2260. (interactive)
  2261. (let ((cname (if (and buffer-file-name
  2262. (string-match "/\\([^/]+\\)\\.e$" buffer-file-name))
  2263. (substring buffer-file-name (match-beginning 1) (match-end 1))
  2264. (read-string "Class: "))))
  2265. (if (not (e-empty-line-p))
  2266. (progn (end-of-line)(newline)))
  2267. (indent-to 0)
  2268. (insert "class " (upcase cname) "\n\n"
  2269. "create {ANY}\n"
  2270. "make\n"
  2271. "\nfeature {ANY}\n\n"
  2272. "\nfeature {}\n"
  2273. "\n\ninvariant\n\n"
  2274. "end -- class " (upcase cname) "\n"))
  2275. (re-search-backward "create {ANY}" nil t)
  2276. (forward-line 1)
  2277. (eif-indent-line)
  2278. (re-search-forward "feature {ANY}" nil t)
  2279. (forward-line 1)
  2280. (eif-indent-line))
  2281. (defun eif-procedure ()
  2282. "Insert a 'procedure' template."
  2283. (interactive)
  2284. (let ((pname (read-string "Procedure name: ")))
  2285. (if (not (e-empty-line-p))
  2286. (progn
  2287. (end-of-line)
  2288. (newline)))
  2289. (indent-to eif-indent-increment)
  2290. (insert pname " is\n")
  2291. (indent-to (* 3 eif-indent-increment))
  2292. (insert "-- \n")
  2293. (mapc #'(lambda (keyword)
  2294. (indent-to (* 2 eif-indent-increment))
  2295. (insert keyword "\n"))
  2296. '("require" "local" "do" "ensure" "end"))
  2297. (search-backward " is" nil t)))
  2298. (defun eif-function ()
  2299. "Insert a 'function' template."
  2300. (interactive)
  2301. (let ((fname (read-string "Function name: "))
  2302. (type (upcase (read-string "Return type: "))))
  2303. (if (not (e-empty-line-p))
  2304. (progn (end-of-line)(newline)))
  2305. (indent-to eif-indent-increment)
  2306. (insert fname ": " type " is\n")
  2307. (indent-to (* 3 eif-indent-increment))
  2308. (insert "-- \n")
  2309. (mapc #'(lambda (keyword)
  2310. (indent-to (* 2 eif-indent-increment))
  2311. (insert keyword "\n"))
  2312. '("require" "local" "do" "ensure" "end"))
  2313. (search-backward ":" nil t)))
  2314. (defun eif-attribute ()
  2315. "Insert an 'attribute' template."
  2316. (interactive)
  2317. (if (not (e-empty-line-p))
  2318. (progn (end-of-line)(newline)))
  2319. (indent-to eif-indent-increment)
  2320. (let ((aname (read-string "Attribute name: "))
  2321. (type (upcase (read-string "Attribute type: "))))
  2322. (insert aname ": " type "\n")
  2323. (indent-to (* 3 eif-indent-increment))
  2324. (insert "-- \n")
  2325. (eif-indent-line)
  2326. (end-of-line)))
  2327. (defun e-empty-line-p ()
  2328. "True if current line is empty."
  2329. (save-excursion
  2330. (beginning-of-line)
  2331. (looking-at "^[ \t]*$")))
  2332. (defun eif-if ()
  2333. "Insert an 'if' statement template."
  2334. (interactive)
  2335. (mapc #'(lambda (s)
  2336. (insert s))
  2337. '("if then" "\n\nelse" "\n\nend" "\n"))
  2338. (re-search-backward " then" nil t)
  2339. (eif-indent-construct))
  2340. (defun eif-loop ()
  2341. "Insert a 'loop' statement template."
  2342. (interactive)
  2343. (let (
  2344. (varname (read-string "Loop variable name: ")
  2345. )
  2346. )
  2347. (if (not (string= varname ""))
  2348. ;; THEN -- A variable is named: insert it
  2349. (
  2350. let ((lower (read-string "Lower bound: "))
  2351. (upper (read-string "Upper bound: "))
  2352. (incr (read-string "Increment: "))
  2353. )
  2354. (insert "from\n" varname " := ")
  2355. (insert lower)
  2356. (insert "\ninvariant")
  2357. (insert "\nvariant\n")
  2358. (if (>= (string-to-number incr) 0)
  2359. (insert "(" upper " - " lower " + " incr ") - " varname)
  2360. (insert varname " - (" upper " - " lower " + " (abs incr) ")")
  2361. )
  2362. (insert "\nuntil\n" varname)
  2363. (if (>= (string-to-number incr) 0)
  2364. (insert " > " upper)
  2365. (insert " < " upper)
  2366. )
  2367. (insert "\nloop\n\n" varname " := " varname)
  2368. (if (>= (string-to-number incr) 0)
  2369. (insert " + " incr)
  2370. (insert " - " (abs incr))
  2371. )
  2372. (insert "\nend\n")
  2373. (re-search-backward "from" nil t)
  2374. (eif-indent-construct)
  2375. (re-search-forward "loop" nil t)
  2376. (forward-line)
  2377. (eif-indent-line)
  2378. )
  2379. ;; ELSE -- No variable: general loop
  2380. (let ()
  2381. (mapc #'(lambda (s)
  2382. (insert s))
  2383. '("from" "\n\ninvariant" "\n\nvariant"
  2384. "\n\nuntil" "\n\nloop\n" "\nend")
  2385. )
  2386. (re-search-backward "from" nil t)
  2387. (eif-indent-construct)
  2388. (forward-line)
  2389. (eif-indent-line)
  2390. )
  2391. )
  2392. )
  2393. )
  2394. (defun eif-set ()
  2395. "Inserts a function to set the value of the given variable."
  2396. (interactive)
  2397. (let ((aname (read-string "Attribute name: ")))
  2398. (insert "set_" aname " (v: like " aname ") is")
  2399. (eif-indent-line)
  2400. (insert "\n-- ")
  2401. (mapc #'(lambda (s)
  2402. (insert s)
  2403. (eif-indent-line))
  2404. (list (concat "Set value of `" aname "'.")
  2405. "\nrequire"
  2406. "\nv /= Void"
  2407. "\ndo"
  2408. (concat "\n" aname " := v")
  2409. "\nensure"
  2410. (concat "\n" aname " = v")
  2411. (concat "\nend;")))
  2412. (insert "\n")))
  2413. (defun eif-inspect ()
  2414. "Insert an 'inspect-when' statement template."
  2415. (interactive)
  2416. (mapc #'(lambda (s)
  2417. (insert s)
  2418. (eif-indent-line))
  2419. '("inspect " "\n\nwhen then" "\n\nelse" "\n\nend" "\n"))
  2420. (beginning-of-line)
  2421. (re-search-backward "inspect" nil t)
  2422. (forward-line)
  2423. (eif-indent-construct)
  2424. (eif-indent-line))
  2425. (defun eif-when ()
  2426. "Insert another 'when-then' clause."
  2427. ;; Obvious improvement -- have this check to see it this is a valid
  2428. ;; location for this construct, before inserting it.
  2429. (interactive)
  2430. (insert "\nwhen then")
  2431. (eif-indent-line)
  2432. (insert "\n\n")
  2433. (re-search-backward " then" nil t))
  2434. (defun eif-elseif ()
  2435. "Insert an 'elseif-then' clause."
  2436. ;; Obvious improvement -- have this check to see it this is a valid
  2437. ;; location for this construct, before inserting it.
  2438. (interactive)
  2439. (insert "\nelseif then")
  2440. (eif-indent-line)
  2441. (insert "\n\n")
  2442. (re-search-backward " then" nil t))
  2443. (defun eif-mark-feature ()
  2444. "Put mark at end of feature, point at beginning."
  2445. (interactive)
  2446. (push-mark (point))
  2447. (eif-end-of-feature)
  2448. (push-mark (point))
  2449. (eif-beginning-of-feature)
  2450. (re-search-backward "^\n" (- (point) 1) t))
  2451. (defun e-comment-line-p ()
  2452. "t if current line is just a comment."
  2453. (save-excursion
  2454. (beginning-of-line)
  2455. (skip-chars-forward " \t")
  2456. (looking-at "--")))
  2457. (defun e-comment-on-line-p ()
  2458. "t if current line contains a comment."
  2459. (save-excursion
  2460. (beginning-of-line)
  2461. (looking-at "[^\n]*--")))
  2462. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2463. ;; XEmacs addition
  2464. ;;;###autoload(add-to-list 'auto-mode-alist '("\\.e\\'" . eiffel-mode))
  2465. (provide 'eiffel)
  2466. ;;; eiffel.el ends here