2011-04-29 17:34:28 +00:00
|
|
|
|
;;; pascal.el --- major mode for editing pascal source in Emacs -*- lexical-binding: t -*-
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
2012-02-08 02:12:24 +00:00
|
|
|
|
;; Copyright (C) 1993-2012 Free Software Foundation, Inc.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
2000-05-18 18:38:09 +00:00
|
|
|
|
;; Author: Espen Skoglund <esk@gnu.org>
|
1995-10-30 17:35:01 +00:00
|
|
|
|
;; Keywords: languages
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1995-10-30 17:35:01 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1995-10-30 17:35:01 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1996-01-15 05:56:38 +00:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
1995-10-30 17:35:01 +00:00
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1995-10-30 17:35:01 +00:00
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; USAGE
|
|
|
|
|
;; =====
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; Emacs should enter Pascal mode when you find a Pascal source file.
|
|
|
|
|
;; When you have entered Pascal mode, you may get more info by pressing
|
|
|
|
|
;; C-h m. You may also get online help describing various functions by:
|
|
|
|
|
;; C-h f <Name of function you want described>
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; If you want to customize Pascal mode to fit you better, you may add
|
|
|
|
|
;; these lines (the values of the variables presented here are the defaults):
|
|
|
|
|
;;
|
|
|
|
|
;; ;; User customization for Pascal mode
|
|
|
|
|
;; (setq pascal-indent-level 3
|
|
|
|
|
;; pascal-case-indent 2
|
|
|
|
|
;; pascal-auto-newline nil
|
|
|
|
|
;; pascal-tab-always-indent t
|
|
|
|
|
;; pascal-auto-endcomments t
|
|
|
|
|
;; pascal-auto-lineup '(all)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
;; pascal-type-keywords '("array" "file" "packed" "char"
|
1997-08-04 19:42:32 +00:00
|
|
|
|
;; "integer" "real" "string" "record")
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; pascal-start-keywords '("begin" "end" "function" "procedure"
|
1997-08-04 19:42:32 +00:00
|
|
|
|
;; "repeat" "until" "while" "read" "readln"
|
|
|
|
|
;; "reset" "rewrite" "write" "writeln")
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; pascal-separator-keywords '("downto" "else" "mod" "div" "then"))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; KNOWN BUGS / BUGREPORTS
|
|
|
|
|
;; =======================
|
|
|
|
|
;; As far as I know, there are no bugs in the current version of this
|
|
|
|
|
;; package. This may not be true however, since I never use this mode
|
|
|
|
|
;; myself and therefore would never notice them anyway. If you do
|
2000-05-18 18:38:09 +00:00
|
|
|
|
;; find any bugs, you may submit them to: esk@gnu.org as well as to
|
|
|
|
|
;; bug-gnu-emacs@gnu.org.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
2009-12-03 01:43:23 +00:00
|
|
|
|
|
1997-04-15 23:38:27 +00:00
|
|
|
|
(defgroup pascal nil
|
2005-07-04 03:17:55 +00:00
|
|
|
|
"Major mode for editing Pascal source in Emacs."
|
2005-11-17 07:40:11 +00:00
|
|
|
|
:link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
|
1997-04-15 23:38:27 +00:00
|
|
|
|
:group 'languages)
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defvar pascal-mode-abbrev-table nil
|
|
|
|
|
"Abbrev table in use in Pascal-mode buffers.")
|
|
|
|
|
(define-abbrev-table 'pascal-mode-abbrev-table ())
|
|
|
|
|
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(defvar pascal-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map ";" 'electric-pascal-semi-or-dot)
|
|
|
|
|
(define-key map "." 'electric-pascal-semi-or-dot)
|
|
|
|
|
(define-key map ":" 'electric-pascal-colon)
|
|
|
|
|
(define-key map "=" 'electric-pascal-equal)
|
|
|
|
|
(define-key map "#" 'electric-pascal-hash)
|
2011-04-29 17:34:28 +00:00
|
|
|
|
;; These are user preferences, so not to set by default.
|
|
|
|
|
;;(define-key map "\r" 'electric-pascal-terminate-line)
|
|
|
|
|
;;(define-key map "\t" 'electric-pascal-tab)
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(define-key map "\M-\t" 'completion-at-point)
|
|
|
|
|
(define-key map "\M-?" 'completion-help-at-point)
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(define-key map "\177" 'backward-delete-char-untabify)
|
|
|
|
|
(define-key map "\M-\C-h" 'pascal-mark-defun)
|
|
|
|
|
(define-key map "\C-c\C-b" 'pascal-insert-block)
|
|
|
|
|
(define-key map "\M-*" 'pascal-star-comment)
|
|
|
|
|
(define-key map "\C-c\C-c" 'pascal-comment-area)
|
|
|
|
|
(define-key map "\C-c\C-u" 'pascal-uncomment-area)
|
|
|
|
|
(define-key map "\M-\C-a" 'pascal-beg-of-defun)
|
|
|
|
|
(define-key map "\M-\C-e" 'pascal-end-of-defun)
|
|
|
|
|
(define-key map "\C-c\C-d" 'pascal-goto-defun)
|
|
|
|
|
(define-key map "\C-c\C-o" 'pascal-outline-mode)
|
|
|
|
|
;; A command to change the whole buffer won't be used terribly
|
|
|
|
|
;; often, so no need for a key binding.
|
|
|
|
|
;; (define-key map "\C-cd" 'pascal-downcase-keywords)
|
|
|
|
|
;; (define-key map "\C-cu" 'pascal-upcase-keywords)
|
|
|
|
|
;; (define-key map "\C-cc" 'pascal-capitalize-keywords)
|
|
|
|
|
map)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
"Keymap used in Pascal mode.")
|
1995-07-27 18:50:02 +00:00
|
|
|
|
|
|
|
|
|
(defvar pascal-imenu-generic-expression
|
2002-02-12 17:38:06 +00:00
|
|
|
|
'((nil "^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" 2))
|
1995-07-27 18:50:02 +00:00
|
|
|
|
"Imenu expression for Pascal-mode. See `imenu-generic-expression'.")
|
1997-04-15 23:30:35 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defvar pascal-keywords
|
2003-02-04 13:24:35 +00:00
|
|
|
|
'("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end"
|
|
|
|
|
"file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of"
|
|
|
|
|
"or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to"
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"type" "until" "var" "while" "with"
|
|
|
|
|
;; The following are not standard in pascal, but widely used.
|
|
|
|
|
"get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write"
|
|
|
|
|
"writeln"))
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Regular expressions used to calculate indent, etc.
|
|
|
|
|
;;;
|
|
|
|
|
(defconst pascal-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
|
|
|
|
|
(defconst pascal-beg-block-re "\\<\\(begin\\|case\\|record\\|repeat\\)\\>")
|
|
|
|
|
(defconst pascal-end-block-re "\\<\\(end\\|until\\)\\>")
|
|
|
|
|
(defconst pascal-declaration-re "\\<\\(const\\|label\\|type\\|var\\)\\>")
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(defconst pascal-progbeg-re "\\<\\program\\>")
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defconst pascal-defun-re "\\<\\(function\\|procedure\\|program\\)\\>")
|
1994-03-01 22:28:47 +00:00
|
|
|
|
(defconst pascal-sub-block-re "\\<\\(if\\|else\\|for\\|while\\|with\\)\\>")
|
1994-03-02 19:41:24 +00:00
|
|
|
|
(defconst pascal-noindent-re "\\<\\(begin\\|end\\|until\\|else\\)\\>")
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defconst pascal-nosemi-re "\\<\\(begin\\|repeat\\|then\\|do\\|else\\)\\>")
|
|
|
|
|
(defconst pascal-autoindent-lines-re
|
|
|
|
|
"\\<\\(label\\|var\\|type\\|const\\|until\\|end\\|begin\\|repeat\\|else\\)\\>")
|
|
|
|
|
|
|
|
|
|
;;; Strings used to mark beginning and end of excluded text
|
|
|
|
|
(defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----")
|
|
|
|
|
(defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}")
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(defvar pascal-mode-syntax-table
|
|
|
|
|
(let ((st (make-syntax-table)))
|
|
|
|
|
(modify-syntax-entry ?\\ "." st)
|
|
|
|
|
(modify-syntax-entry ?\( "()1" st)
|
|
|
|
|
(modify-syntax-entry ?\) ")(4" st)
|
|
|
|
|
;; This used to use comment-syntax `b'. But the only document I could
|
|
|
|
|
;; find about the syntax of Pascal's comments said that (* ... } is
|
|
|
|
|
;; a valid comment, just as { ... *) or (* ... *) or { ... }.
|
|
|
|
|
(modify-syntax-entry ?* ". 23" st)
|
|
|
|
|
(modify-syntax-entry ?{ "<" st)
|
|
|
|
|
(modify-syntax-entry ?} ">" st)
|
|
|
|
|
(modify-syntax-entry ?+ "." st)
|
|
|
|
|
(modify-syntax-entry ?- "." st)
|
|
|
|
|
(modify-syntax-entry ?= "." st)
|
|
|
|
|
(modify-syntax-entry ?% "." st)
|
|
|
|
|
(modify-syntax-entry ?< "." st)
|
|
|
|
|
(modify-syntax-entry ?> "." st)
|
|
|
|
|
(modify-syntax-entry ?& "." st)
|
|
|
|
|
(modify-syntax-entry ?| "." st)
|
|
|
|
|
(modify-syntax-entry ?_ "_" st)
|
|
|
|
|
(modify-syntax-entry ?\' "\"" st)
|
|
|
|
|
st)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
"Syntax table in use in Pascal-mode buffers.")
|
|
|
|
|
|
2005-10-10 17:14:02 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(defconst pascal-font-lock-keywords (purecopy
|
1994-10-07 10:10:07 +00:00
|
|
|
|
(list
|
1997-08-04 19:42:32 +00:00
|
|
|
|
'("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\([a-z]\\)"
|
|
|
|
|
1 font-lock-keyword-face)
|
|
|
|
|
'("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\([a-z][a-z0-9_]*\\)"
|
|
|
|
|
3 font-lock-function-name-face t)
|
1994-10-07 10:10:07 +00:00
|
|
|
|
; ("type" "const" "real" "integer" "char" "boolean" "var"
|
|
|
|
|
; "record" "array" "file")
|
|
|
|
|
(cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|"
|
|
|
|
|
"integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>")
|
|
|
|
|
'font-lock-type-face)
|
1998-02-20 14:58:27 +00:00
|
|
|
|
'("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-constant-face)
|
1997-08-04 19:42:32 +00:00
|
|
|
|
'("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-function-name-face)
|
1994-10-07 10:10:07 +00:00
|
|
|
|
; ("of" "to" "for" "if" "then" "else" "case" "while"
|
|
|
|
|
; "do" "until" "and" "or" "not" "in" "with" "repeat" "begin" "end")
|
|
|
|
|
(concat "\\<\\("
|
|
|
|
|
"and\\|begin\\|case\\|do\\|e\\(lse\\|nd\\)\\|for\\|i[fn]\\|"
|
|
|
|
|
"not\\|o[fr]\\|repeat\\|t\\(hen\\|o\\)\\|until\\|w\\(hile\\|ith\\)"
|
|
|
|
|
"\\)\\>")
|
|
|
|
|
'("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
|
1997-08-04 19:42:32 +00:00
|
|
|
|
1 font-lock-keyword-face)
|
|
|
|
|
'("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
|
|
|
|
|
2 font-lock-keyword-face t)))
|
1994-10-07 10:10:07 +00:00
|
|
|
|
"Additional expressions to highlight in Pascal mode.")
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(put 'pascal-mode 'font-lock-defaults '(pascal-font-lock-keywords nil t))
|
1994-10-07 10:10:07 +00:00
|
|
|
|
|
1997-04-15 23:38:27 +00:00
|
|
|
|
(defcustom pascal-indent-level 3
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Indentation of Pascal statements with respect to containing block."
|
1997-04-15 23:38:27 +00:00
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
|
|
|
|
(defcustom pascal-case-indent 2
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Indentation for case statements."
|
1997-04-15 23:38:27 +00:00
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
|
|
|
|
(defcustom pascal-auto-newline nil
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Non-nil means automatically insert newlines in certain cases.
|
1997-04-15 23:38:27 +00:00
|
|
|
|
These include after semicolons and after the punctuation mark after an `end'."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(defcustom pascal-indent-nested-functions t
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Non-nil means nested functions are indented."
|
1999-07-12 16:14:13 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
1997-04-15 23:38:27 +00:00
|
|
|
|
(defcustom pascal-tab-always-indent t
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Non-nil means TAB in Pascal mode should always reindent the current line.
|
1997-04-15 23:38:27 +00:00
|
|
|
|
If this is nil, TAB inserts a tab if it is at the end of the line
|
|
|
|
|
and follows non-whitespace text."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
|
|
|
|
(defcustom pascal-auto-endcomments t
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Non-nil means automatically insert comments after certain `end's.
|
1997-04-15 23:38:27 +00:00
|
|
|
|
Specifically, this is done after the ends of cases statements and functions.
|
|
|
|
|
The name of the function or case is included between the braces."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
|
|
|
|
(defcustom pascal-auto-lineup '(all)
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"List of contexts where auto lineup of :'s or ='s should be done.
|
1994-09-03 03:34:55 +00:00
|
|
|
|
Elements can be of type: 'paramlist', 'declaration' or 'case', which will
|
|
|
|
|
do auto lineup in parameterlist, declarations or case-statements
|
2010-09-20 14:57:01 +00:00
|
|
|
|
respectively. The word 'all' will do all lineups. '(case paramlist) for
|
1994-09-03 03:34:55 +00:00
|
|
|
|
instance will do lineup in case-statements and parameterlist, while '(all)
|
1997-04-15 23:38:27 +00:00
|
|
|
|
will do all lineups."
|
1999-07-12 16:14:13 +00:00
|
|
|
|
:type '(set :extra-offset 8
|
|
|
|
|
(const :tag "Everything" all)
|
|
|
|
|
(const :tag "Parameter lists" paramlist)
|
2011-11-11 10:04:08 +00:00
|
|
|
|
(const :tag "Declarations" declaration)
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(const :tag "Case statements" case))
|
1997-04-15 23:38:27 +00:00
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(defvar pascal-toggle-completions nil
|
2012-06-12 05:47:14 +00:00
|
|
|
|
"If non-nil, `pascal-complete-word' tries all possible completions.
|
|
|
|
|
Repeated use of \\[pascal-complete-word] then shows all
|
|
|
|
|
completions in turn, instead of displaying a list of all possible
|
|
|
|
|
completions.")
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(make-obsolete-variable 'pascal-toggle-completions
|
|
|
|
|
'completion-cycle-threshold "24.1")
|
1994-09-03 03:34:55 +00:00
|
|
|
|
|
1997-04-15 23:38:27 +00:00
|
|
|
|
(defcustom pascal-type-keywords
|
1994-02-01 18:14:56 +00:00
|
|
|
|
'("array" "file" "packed" "char" "integer" "real" "string" "record")
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Keywords for types used when completing a word in a declaration or parmlist.
|
1997-04-15 23:38:27 +00:00
|
|
|
|
These include integer, real, char, etc.
|
|
|
|
|
The types defined within the Pascal program
|
|
|
|
|
are handled in another way, and should not be added to this list."
|
|
|
|
|
:type '(repeat (string :tag "Keyword"))
|
|
|
|
|
:group 'pascal)
|
1994-09-03 03:34:55 +00:00
|
|
|
|
|
1997-04-15 23:38:27 +00:00
|
|
|
|
(defcustom pascal-start-keywords
|
1994-02-01 18:14:56 +00:00
|
|
|
|
'("begin" "end" "function" "procedure" "repeat" "until" "while"
|
|
|
|
|
"read" "readln" "reset" "rewrite" "write" "writeln")
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Keywords to complete when standing at the first word of a statement.
|
1997-04-15 23:38:27 +00:00
|
|
|
|
These are keywords such as begin, repeat, until, readln.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
The procedures and variables defined within the Pascal program
|
2002-09-06 07:16:42 +00:00
|
|
|
|
are handled in another way, and should not be added to this list."
|
1997-04-15 23:38:27 +00:00
|
|
|
|
:type '(repeat (string :tag "Keyword"))
|
|
|
|
|
:group 'pascal)
|
1994-09-03 03:34:55 +00:00
|
|
|
|
|
1997-04-15 23:38:27 +00:00
|
|
|
|
(defcustom pascal-separator-keywords
|
1994-02-01 18:14:56 +00:00
|
|
|
|
'("downto" "else" "mod" "div" "then")
|
2012-04-09 13:05:48 +00:00
|
|
|
|
"Keywords to complete when NOT standing at the first word of a statement.
|
1997-04-15 23:38:27 +00:00
|
|
|
|
These are keywords such as downto, else, mod, then.
|
|
|
|
|
Variables and function names defined within the Pascal program
|
|
|
|
|
are handled in another way, and should not be added to this list."
|
|
|
|
|
:type '(repeat (string :tag "Keyword"))
|
|
|
|
|
:group 'pascal)
|
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Macros
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(defun pascal-declaration-end ()
|
|
|
|
|
(let ((nest 1))
|
|
|
|
|
(while (and (> nest 0)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(re-search-forward
|
|
|
|
|
"[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)"
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(point-at-eol 2) t))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(cond ((match-beginning 1) (setq nest (1+ nest)))
|
1996-03-07 05:53:10 +00:00
|
|
|
|
((match-beginning 2) (setq nest (1- nest)))
|
|
|
|
|
((looking-at "[^(\n]+)") (setq nest 0))))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
1994-09-03 03:34:55 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defun pascal-declaration-beg ()
|
|
|
|
|
(let ((nest 1))
|
|
|
|
|
(while (and (> nest 0)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(re-search-backward "[:=]\\|\\<\\(type\\|var\\|label\\|const\\)\\>\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)" (point-at-bol 0) t))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(cond ((match-beginning 1) (setq nest 0))
|
|
|
|
|
((match-beginning 2) (setq nest (1- nest)))
|
|
|
|
|
((match-beginning 3) (setq nest (1+ nest)))))
|
|
|
|
|
(= nest 0)))
|
1994-09-03 03:34:55 +00:00
|
|
|
|
|
2003-02-04 13:24:35 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defsubst pascal-within-string ()
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(nth 3 (parse-partial-sexp (point-at-bol) (point))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(define-derived-mode pascal-mode prog-mode "Pascal"
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Major mode for editing Pascal code. \\<pascal-mode-map>
|
|
|
|
|
TAB indents for Pascal code. Delete converts tabs to spaces as it moves back.
|
|
|
|
|
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
\\[completion-at-point] completes the word around current point with respect \
|
1994-02-01 18:14:56 +00:00
|
|
|
|
to position in code
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
\\[completion-help-at-point] shows all possible completions at this point.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
Other useful functions are:
|
|
|
|
|
|
|
|
|
|
\\[pascal-mark-defun]\t- Mark function.
|
|
|
|
|
\\[pascal-insert-block]\t- insert begin ... end;
|
|
|
|
|
\\[pascal-star-comment]\t- insert (* ... *)
|
|
|
|
|
\\[pascal-comment-area]\t- Put marked area in a comment, fixing nested comments.
|
|
|
|
|
\\[pascal-uncomment-area]\t- Uncomment an area commented with \
|
|
|
|
|
\\[pascal-comment-area].
|
|
|
|
|
\\[pascal-beg-of-defun]\t- Move to beginning of current function.
|
|
|
|
|
\\[pascal-end-of-defun]\t- Move to end of current function.
|
|
|
|
|
\\[pascal-goto-defun]\t- Goto function prompted for in the minibuffer.
|
2005-10-10 17:14:02 +00:00
|
|
|
|
\\[pascal-outline-mode]\t- Enter `pascal-outline-mode'.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
Variables controlling indentation/edit style:
|
|
|
|
|
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-indent-level' (default 3)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
Indentation of Pascal statements with respect to containing block.
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-case-indent' (default 2)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
Indentation for case statements.
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-auto-newline' (default nil)
|
1996-01-04 23:46:19 +00:00
|
|
|
|
Non-nil means automatically newline after semicolons and the punctuation
|
|
|
|
|
mark after an end.
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-indent-nested-functions' (default t)
|
1999-07-12 16:14:13 +00:00
|
|
|
|
Non-nil means nested functions are indented.
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-tab-always-indent' (default t)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
Non-nil means TAB in Pascal mode should always reindent the current line,
|
|
|
|
|
regardless of where in the line point is when the TAB command is used.
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-auto-endcomments' (default t)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
Non-nil means a comment { ... } is set after the ends which ends cases and
|
|
|
|
|
functions. The name of the function or case will be set between the braces.
|
2010-09-20 14:57:01 +00:00
|
|
|
|
`pascal-auto-lineup' (default t)
|
1997-04-15 23:30:35 +00:00
|
|
|
|
List of contexts where auto lineup of :'s or ='s should be done.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
2010-09-20 14:57:01 +00:00
|
|
|
|
See also the user variables `pascal-type-keywords', `pascal-start-keywords' and
|
|
|
|
|
`pascal-separator-keywords'.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
Turning on Pascal mode calls the value of the variable pascal-mode-hook with
|
|
|
|
|
no args, if that value is non-nil."
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(set (make-local-variable 'local-abbrev-table) pascal-mode-abbrev-table)
|
|
|
|
|
(set (make-local-variable 'indent-line-function) 'pascal-indent-line)
|
|
|
|
|
(set (make-local-variable 'comment-indent-function) 'pascal-indent-comment)
|
|
|
|
|
(set (make-local-variable 'parse-sexp-ignore-comments) nil)
|
|
|
|
|
(set (make-local-variable 'blink-matching-paren-dont-ignore-comments) t)
|
|
|
|
|
(set (make-local-variable 'case-fold-search) t)
|
|
|
|
|
(set (make-local-variable 'comment-start) "{")
|
|
|
|
|
(set (make-local-variable 'comment-start-skip) "(\\*+ *\\|{ *")
|
|
|
|
|
(set (make-local-variable 'comment-end) "}")
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(add-hook 'completion-at-point-functions 'pascal-completions-at-point nil t)
|
1995-07-27 18:50:02 +00:00
|
|
|
|
;; Font lock support
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(set (make-local-variable 'font-lock-defaults)
|
|
|
|
|
'(pascal-font-lock-keywords nil t))
|
1995-07-27 18:50:02 +00:00
|
|
|
|
;; Imenu support
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(set (make-local-variable 'imenu-generic-expression)
|
|
|
|
|
pascal-imenu-generic-expression)
|
|
|
|
|
(set (make-local-variable 'imenu-case-fold-search) t)
|
|
|
|
|
;; Pascal-mode's own hide/show support.
|
|
|
|
|
(add-to-invisibility-spec '(pascal . t)))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; Electric functions
|
|
|
|
|
;;;
|
|
|
|
|
(defun electric-pascal-terminate-line ()
|
|
|
|
|
"Terminate line and indent next line."
|
|
|
|
|
(interactive)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; First, check if current line should be indented
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(skip-chars-forward " \t")
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (looking-at pascal-autoindent-lines-re)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(pascal-indent-line)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(delete-horizontal-space) ; Removes trailing whitespaces
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(newline)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Indent next line
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(pascal-indent-line)
|
|
|
|
|
;; Maybe we should set some endcomments
|
|
|
|
|
(if pascal-auto-endcomments
|
|
|
|
|
(pascal-set-auto-comments))
|
|
|
|
|
;; Check if we shall indent inside comment
|
|
|
|
|
(let ((setstar nil))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(skip-chars-forward " \t")
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(cond ((looking-at "\\*[ \t]+)")
|
1993-11-08 14:46:50 +00:00
|
|
|
|
;; Delete region between `*' and `)' if there is only whitespaces.
|
|
|
|
|
(forward-char 1)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(delete-horizontal-space))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
((and (looking-at "(\\*\\|\\*[^)]")
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(not (save-excursion (search-forward "*)" (point-at-eol) t))))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(setq setstar t))))
|
|
|
|
|
;; If last line was a star comment line then this one shall be too.
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(if (null setstar)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-indent-line)
|
|
|
|
|
(insert "* "))))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defun electric-pascal-semi-or-dot ()
|
|
|
|
|
"Insert `;' or `.' character and reindent the line."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
2009-01-09 04:23:38 +00:00
|
|
|
|
(insert last-command-event)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(pascal-indent-line))
|
|
|
|
|
(if pascal-auto-newline
|
|
|
|
|
(electric-pascal-terminate-line)))
|
|
|
|
|
|
|
|
|
|
(defun electric-pascal-colon ()
|
2011-11-19 09:18:31 +00:00
|
|
|
|
"Insert `:' and do all indentations except line indent on this line."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
2009-01-09 04:23:38 +00:00
|
|
|
|
(insert last-command-event)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Do nothing if within string.
|
|
|
|
|
(if (pascal-within-string)
|
|
|
|
|
()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(pascal-indent-line))
|
|
|
|
|
(let ((pascal-tab-always-indent nil))
|
|
|
|
|
(pascal-indent-command))))
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defun electric-pascal-equal ()
|
2011-11-20 03:48:53 +00:00
|
|
|
|
"Insert `=', and do indentation if within type declaration."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
2009-01-09 04:23:38 +00:00
|
|
|
|
(insert last-command-event)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (eq (car (pascal-calculate-indent)) 'declaration)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(let ((pascal-tab-always-indent nil))
|
|
|
|
|
(pascal-indent-command))))
|
|
|
|
|
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(defun electric-pascal-hash ()
|
1996-01-04 23:46:19 +00:00
|
|
|
|
"Insert `#', and indent to column 0 if this is a CPP directive."
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(interactive)
|
2009-01-09 04:23:38 +00:00
|
|
|
|
(insert last-command-event)
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(if (save-excursion (beginning-of-line) (looking-at "^[ \t]*#"))
|
|
|
|
|
(save-excursion (beginning-of-line)
|
|
|
|
|
(delete-horizontal-space))))
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defun electric-pascal-tab ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Function called when TAB is pressed in Pascal mode."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
1995-01-17 20:53:31 +00:00
|
|
|
|
;; Do nothing if within a string or in a CPP directive.
|
|
|
|
|
(if (or (pascal-within-string)
|
|
|
|
|
(and (not (bolp))
|
|
|
|
|
(save-excursion (beginning-of-line) (eq (following-char) ?#))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(insert "\t")
|
|
|
|
|
;; If pascal-tab-always-indent, indent the beginning of the line.
|
|
|
|
|
(if pascal-tab-always-indent
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(pascal-indent-line))
|
1996-03-07 05:53:10 +00:00
|
|
|
|
(if (save-excursion
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(bolp))
|
|
|
|
|
(pascal-indent-line)
|
|
|
|
|
(insert "\t")))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-indent-command)))
|
|
|
|
|
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Interactive functions
|
|
|
|
|
;;;
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(defvar pascal--extra-indent 0)
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defun pascal-insert-block ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Insert Pascal begin ... end; block in the code with right indentation."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(insert "begin")
|
|
|
|
|
(electric-pascal-terminate-line)
|
|
|
|
|
(save-excursion
|
1998-07-03 20:10:32 +00:00
|
|
|
|
(newline)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(insert "end;")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(pascal-indent-line)))
|
|
|
|
|
|
|
|
|
|
(defun pascal-star-comment ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Insert Pascal star comment at point."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-indent-line)
|
|
|
|
|
(insert "(*")
|
|
|
|
|
(electric-pascal-terminate-line)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(electric-pascal-terminate-line)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(insert ")"))
|
|
|
|
|
(insert " "))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defun pascal-mark-defun ()
|
1993-11-08 14:46:50 +00:00
|
|
|
|
"Mark the current pascal function (or procedure).
|
1994-02-01 18:14:56 +00:00
|
|
|
|
This puts the mark at the end, and point at the beginning."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(push-mark (point))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-end-of-defun)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(push-mark (point))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-beg-of-defun)
|
2008-01-24 15:14:52 +00:00
|
|
|
|
(when (featurep 'xemacs)
|
|
|
|
|
(zmacs-activate-region)))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-comment-area (start end)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Put the region into a Pascal comment.
|
|
|
|
|
The comments that are in this area are \"deformed\":
|
|
|
|
|
`*)' becomes `!(*' and `}' becomes `!{'.
|
|
|
|
|
These deformed comments are returned to normal if you use
|
|
|
|
|
\\[pascal-uncomment-area] to undo the commenting.
|
|
|
|
|
|
|
|
|
|
The commented area starts with `pascal-exclude-str-start', and ends with
|
|
|
|
|
`pascal-include-str-end'. But if you change these variables,
|
|
|
|
|
\\[pascal-uncomment-area] won't recognize the comments."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive "r")
|
|
|
|
|
(save-excursion
|
|
|
|
|
;; Insert start and endcomments
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(if (and (save-excursion (skip-chars-forward " \t") (eolp))
|
|
|
|
|
(not (save-excursion (skip-chars-backward " \t") (bolp))))
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(beginning-of-line))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(insert pascal-exclude-str-end)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(setq end (point))
|
|
|
|
|
(newline)
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(beginning-of-line)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(insert pascal-exclude-str-start)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(newline)
|
|
|
|
|
;; Replace end-comments within commented area
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (re-search-backward "\\*)" start t)
|
|
|
|
|
(replace-match "!(*" t t)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (re-search-backward "}" start t)
|
|
|
|
|
(replace-match "!{" t t)))))
|
|
|
|
|
|
|
|
|
|
(defun pascal-uncomment-area ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Uncomment a commented area; change deformed comments back to normal.
|
|
|
|
|
This command does nothing if the pointer is not in a commented
|
1993-11-08 14:46:50 +00:00
|
|
|
|
area. See also `pascal-comment-area'."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((start (point))
|
|
|
|
|
(end (point)))
|
|
|
|
|
;; Find the boundaries of the comment
|
|
|
|
|
(save-excursion
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(setq start (progn (search-backward pascal-exclude-str-start nil t)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(point)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(setq end (progn (search-forward pascal-exclude-str-end nil t)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(point))))
|
|
|
|
|
;; Check if we're really inside a comment
|
|
|
|
|
(if (or (equal start (point)) (<= end (point)))
|
|
|
|
|
(message "Not standing within commented area.")
|
|
|
|
|
(progn
|
|
|
|
|
;; Remove endcomment
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((pos (point)))
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(delete-region pos (1+ (point))))
|
|
|
|
|
;; Change comments back to normal
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (re-search-backward "!{" start t)
|
|
|
|
|
(replace-match "}" t t)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (re-search-backward "!(\\*" start t)
|
|
|
|
|
(replace-match "*)" t t)))
|
|
|
|
|
;; Remove startcomment
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((pos (point)))
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(delete-region pos (1+ (point)))))))))
|
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defun pascal-beg-of-defun ()
|
|
|
|
|
"Move backward to the beginning of the current function or procedure."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(catch 'found
|
|
|
|
|
(if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))
|
|
|
|
|
(forward-sexp 1))
|
|
|
|
|
(let ((nest 0) (max -1) (func 0)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(reg (concat pascal-beg-block-re "\\|"
|
1994-02-01 18:14:56 +00:00
|
|
|
|
pascal-end-block-re "\\|"
|
|
|
|
|
pascal-defun-re)))
|
|
|
|
|
(while (re-search-backward reg nil 'move)
|
|
|
|
|
(cond ((let ((state (save-excursion
|
|
|
|
|
(parse-partial-sexp (point-min) (point)))))
|
|
|
|
|
(or (nth 3 state) (nth 4 state))) ; Inside string or comment
|
|
|
|
|
())
|
|
|
|
|
((match-end 1) ; begin|case|record|repeat
|
|
|
|
|
(if (and (looking-at "\\<record\\>") (>= max 0))
|
|
|
|
|
(setq func (1- func)))
|
|
|
|
|
(setq nest (1+ nest)
|
|
|
|
|
max (max nest max)))
|
|
|
|
|
((match-end 2) ; end|until
|
|
|
|
|
(if (and (= nest max) (>= max 0))
|
|
|
|
|
(setq func (1+ func)))
|
|
|
|
|
(setq nest (1- nest)))
|
|
|
|
|
((match-end 3) ; function|procedure
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(if (= 0 func)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(throw 'found t)
|
|
|
|
|
(setq func (1- func)))))))
|
|
|
|
|
nil))
|
|
|
|
|
|
|
|
|
|
(defun pascal-end-of-defun ()
|
|
|
|
|
"Move forward to the end of the current function or procedure."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (looking-at "\\s ")
|
|
|
|
|
(forward-sexp 1))
|
|
|
|
|
(if (not (looking-at pascal-defun-re))
|
|
|
|
|
(pascal-beg-of-defun))
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(let ((nest 0) (func 1)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(reg (concat pascal-beg-block-re "\\|"
|
1994-02-01 18:14:56 +00:00
|
|
|
|
pascal-end-block-re "\\|"
|
|
|
|
|
pascal-defun-re)))
|
|
|
|
|
(while (and (/= func 0)
|
|
|
|
|
(re-search-forward reg nil 'move))
|
|
|
|
|
(cond ((let ((state (save-excursion
|
|
|
|
|
(parse-partial-sexp (point-min) (point)))))
|
|
|
|
|
(or (nth 3 state) (nth 4 state))) ; Inside string or comment
|
|
|
|
|
())
|
|
|
|
|
((match-end 1)
|
|
|
|
|
(setq nest (1+ nest))
|
|
|
|
|
(if (save-excursion
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(looking-at "\\<record\\>"))
|
|
|
|
|
(setq func (1+ func))))
|
|
|
|
|
((match-end 2)
|
|
|
|
|
(setq nest (1- nest))
|
|
|
|
|
(if (= nest 0)
|
|
|
|
|
(setq func (1- func))))
|
|
|
|
|
((match-end 3)
|
|
|
|
|
(setq func (1+ func))))))
|
|
|
|
|
(forward-line 1))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1994-09-03 03:34:55 +00:00
|
|
|
|
(defun pascal-end-of-statement ()
|
|
|
|
|
"Move forward to end of current statement."
|
|
|
|
|
(interactive)
|
1996-05-13 16:25:13 +00:00
|
|
|
|
(let ((parse-sexp-ignore-comments t)
|
|
|
|
|
(nest 0) pos
|
1994-09-03 03:34:55 +00:00
|
|
|
|
(regexp (concat "\\(" pascal-beg-block-re "\\)\\|\\("
|
|
|
|
|
pascal-end-block-re "\\)")))
|
|
|
|
|
(if (not (looking-at "[ \t\n]")) (forward-sexp -1))
|
|
|
|
|
(or (looking-at pascal-beg-block-re)
|
|
|
|
|
;; Skip to end of statement
|
|
|
|
|
(setq pos (catch 'found
|
|
|
|
|
(while t
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
(cond ((looking-at "[ \t]*;")
|
|
|
|
|
(skip-chars-forward "^;")
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(throw 'found (point)))
|
|
|
|
|
((save-excursion
|
|
|
|
|
(forward-sexp -1)
|
|
|
|
|
(looking-at pascal-beg-block-re))
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(throw 'found nil))
|
|
|
|
|
((eobp)
|
|
|
|
|
(throw 'found (point))))))))
|
|
|
|
|
(if (not pos)
|
|
|
|
|
;; Skip a whole block
|
|
|
|
|
(catch 'found
|
|
|
|
|
(while t
|
|
|
|
|
(re-search-forward regexp nil 'move)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(setq nest (if (match-end 1)
|
1994-09-03 03:34:55 +00:00
|
|
|
|
(1+ nest)
|
|
|
|
|
(1- nest)))
|
|
|
|
|
(cond ((eobp)
|
|
|
|
|
(throw 'found (point)))
|
|
|
|
|
((= 0 nest)
|
|
|
|
|
(throw 'found (pascal-end-of-statement))))))
|
|
|
|
|
pos)))
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defun pascal-downcase-keywords ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Downcase all Pascal keywords in the buffer."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-change-keywords 'downcase-word))
|
|
|
|
|
|
|
|
|
|
(defun pascal-upcase-keywords ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Upcase all Pascal keywords in the buffer."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-change-keywords 'upcase-word))
|
|
|
|
|
|
|
|
|
|
(defun pascal-capitalize-keywords ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Capitalize all Pascal keywords in the buffer."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-change-keywords 'capitalize-word))
|
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Change the keywords according to argument.
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defun pascal-change-keywords (change-word)
|
|
|
|
|
(save-excursion
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(let ((keyword-re (concat "\\<\\("
|
|
|
|
|
(mapconcat 'identity pascal-keywords "\\|")
|
|
|
|
|
"\\)\\>")))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (re-search-forward keyword-re nil t)
|
|
|
|
|
(funcall change-word -1)))))
|
|
|
|
|
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Other functions
|
|
|
|
|
;;;
|
|
|
|
|
(defun pascal-set-auto-comments ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Insert `{ case }' or `{ NAME }' on this line if appropriate.
|
|
|
|
|
Insert `{ case }' if there is an `end' on the line which
|
|
|
|
|
ends a case block. Insert `{ NAME }' if there is an `end'
|
|
|
|
|
on the line which ends a function or procedure named NAME."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(skip-chars-forward " \t")
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (and (looking-at "\\<end;")
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(not (save-excursion
|
|
|
|
|
(end-of-line)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(search-backward "{" (point-at-bol) t))))
|
1994-03-12 06:29:57 +00:00
|
|
|
|
(let ((type (car (pascal-calculate-indent))))
|
|
|
|
|
(if (eq type 'declaration)
|
|
|
|
|
()
|
|
|
|
|
(if (eq type 'case)
|
|
|
|
|
;; This is a case block
|
|
|
|
|
(progn
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(insert " { case }"))
|
|
|
|
|
(let ((nest 1))
|
|
|
|
|
;; Check if this is the end of a function
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (not (or (looking-at pascal-defun-re) (bobp)))
|
|
|
|
|
(backward-sexp 1)
|
|
|
|
|
(cond ((looking-at pascal-beg-block-re)
|
|
|
|
|
(setq nest (1- nest)))
|
|
|
|
|
((looking-at pascal-end-block-re)
|
|
|
|
|
(setq nest (1+ nest)))))
|
|
|
|
|
(if (bobp)
|
|
|
|
|
(setq nest 1)))
|
|
|
|
|
(if (zerop nest)
|
|
|
|
|
(progn
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(insert " { ")
|
|
|
|
|
(let (b e)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(setq b (progn (pascal-beg-of-defun)
|
|
|
|
|
(skip-chars-forward "^ \t")
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(point))
|
|
|
|
|
e (progn (skip-chars-forward "a-zA-Z0-9_")
|
|
|
|
|
(point))))
|
|
|
|
|
(insert-buffer-substring (current-buffer) b e))
|
|
|
|
|
(insert " }"))))))))))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
;;;
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;;; Indentation
|
|
|
|
|
;;;
|
|
|
|
|
(defconst pascal-indent-alist
|
2012-04-27 02:48:38 +00:00
|
|
|
|
'((block . (+ pascal--extra-indent pascal-indent-level))
|
|
|
|
|
(case . (+ pascal--extra-indent pascal-case-indent))
|
|
|
|
|
(caseblock . pascal--extra-indent) (cpp . 0)
|
|
|
|
|
(declaration . (+ pascal--extra-indent pascal-indent-level))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(paramlist . (pascal-indent-paramlist t))
|
2000-05-18 18:38:09 +00:00
|
|
|
|
(comment . (pascal-indent-comment))
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(defun . pascal--extra-indent) (contexp . pascal--extra-indent)
|
|
|
|
|
(unknown . pascal--extra-indent) (string . 0) (progbeg . 0)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(defun pascal-indent-command ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Indent for special part of code."
|
|
|
|
|
(let* ((indent-str (pascal-calculate-indent))
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(type (car indent-str)))
|
1994-09-03 03:34:55 +00:00
|
|
|
|
(cond ((and (eq type 'paramlist)
|
|
|
|
|
(or (memq 'all pascal-auto-lineup)
|
|
|
|
|
(memq 'paramlist pascal-auto-lineup)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-indent-paramlist)
|
|
|
|
|
(pascal-indent-paramlist))
|
1994-09-03 03:34:55 +00:00
|
|
|
|
((and (eq type 'declaration)
|
|
|
|
|
(or (memq 'all pascal-auto-lineup)
|
|
|
|
|
(memq 'declaration pascal-auto-lineup)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-indent-declaration))
|
1994-09-03 03:34:55 +00:00
|
|
|
|
((and (eq type 'case) (not (looking-at "^[ \t]*$"))
|
|
|
|
|
(or (memq 'all pascal-auto-lineup)
|
|
|
|
|
(memq 'case pascal-auto-lineup)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-indent-case)))
|
|
|
|
|
(if (looking-at "[ \t]+$")
|
|
|
|
|
(skip-chars-forward " \t"))))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-indent-line ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Indent current line as a Pascal statement."
|
|
|
|
|
(let* ((indent-str (pascal-calculate-indent))
|
|
|
|
|
(type (car indent-str))
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(pascal--extra-indent (car (cdr indent-str))))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
;; Labels should not be indented.
|
|
|
|
|
(if (and (looking-at "^[0-9a-zA-Z]+[ \t]*:[^=]")
|
|
|
|
|
(not (eq type 'declaration)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(search-forward ":" nil t))
|
|
|
|
|
(delete-horizontal-space)
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(cond (; Some things should not be indented
|
|
|
|
|
(or (and (eq type 'declaration) (looking-at pascal-declaration-re))
|
|
|
|
|
(eq type 'cpp))
|
|
|
|
|
())
|
|
|
|
|
(; Other things should have no extra indent
|
|
|
|
|
(looking-at pascal-noindent-re)
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(indent-to pascal--extra-indent))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(; Nested functions should be indented
|
|
|
|
|
(looking-at pascal-defun-re)
|
|
|
|
|
(if (and pascal-indent-nested-functions
|
|
|
|
|
(eq type 'defun))
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(indent-to (+ pascal--extra-indent pascal-indent-level))
|
|
|
|
|
(indent-to pascal--extra-indent)))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(; But most lines are treated this way
|
|
|
|
|
(indent-to (eval (cdr (assoc type pascal-indent-alist))))
|
|
|
|
|
))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-calculate-indent ()
|
|
|
|
|
"Calculate the indent of the current Pascal line.
|
|
|
|
|
Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
|
|
|
|
|
(save-excursion
|
1996-05-13 16:25:13 +00:00
|
|
|
|
(let* ((parse-sexp-ignore-comments t)
|
|
|
|
|
(oldpos (point))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(state (save-excursion (parse-partial-sexp (point-min) (point))))
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(nest 0) (par 0) (complete (looking-at "[ \t]*end\\>"))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(elsed (looking-at "[ \t]*else\\>")) (funccnt 0)
|
|
|
|
|
(did-func (looking-at "[ \t]*\\(procedure\\|function\\)\\>"))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(type (catch 'nesting
|
|
|
|
|
;; Check if inside a string, comment or parenthesis
|
|
|
|
|
(cond ((nth 3 state) (throw 'nesting 'string))
|
|
|
|
|
((nth 4 state) (throw 'nesting 'comment))
|
|
|
|
|
((> (car state) 0)
|
|
|
|
|
(goto-char (scan-lists (point) -1 (car state)))
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(setq par (1+ (current-column))))
|
|
|
|
|
((save-excursion (beginning-of-line)
|
|
|
|
|
(eq (following-char) ?#))
|
|
|
|
|
(throw 'nesting 'cpp)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Loop until correct indent is found
|
|
|
|
|
(while t
|
|
|
|
|
(backward-sexp 1)
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(cond (;--Escape from case statements
|
|
|
|
|
(and (looking-at "[A-Za-z0-9]+[ \t]*:[^=]")
|
|
|
|
|
(not complete)
|
|
|
|
|
(save-excursion (skip-chars-backward " \t")
|
|
|
|
|
(bolp))
|
|
|
|
|
(= (save-excursion
|
|
|
|
|
(end-of-line) (backward-sexp) (point))
|
|
|
|
|
(point))
|
|
|
|
|
(> (save-excursion (goto-char oldpos)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(point))
|
|
|
|
|
(point)))
|
|
|
|
|
(throw 'nesting 'caseblock))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(;--Beginning of program
|
|
|
|
|
(looking-at pascal-progbeg-re)
|
|
|
|
|
(throw 'nesting 'progbeg))
|
|
|
|
|
(;--No known statements
|
|
|
|
|
(bobp)
|
|
|
|
|
(throw 'nesting 'progbeg))
|
1995-01-17 20:53:31 +00:00
|
|
|
|
(;--Nest block outwards
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(looking-at pascal-beg-block-re)
|
|
|
|
|
(if (= nest 0)
|
|
|
|
|
(cond ((looking-at "case\\>")
|
|
|
|
|
(throw 'nesting 'case))
|
|
|
|
|
((looking-at "record\\>")
|
|
|
|
|
(throw 'nesting 'declaration))
|
1994-03-02 19:41:24 +00:00
|
|
|
|
(t (throw 'nesting 'block)))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(if (and (looking-at "record\\>") (= nest 1))
|
|
|
|
|
(setq funccnt (1- funccnt)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(setq nest (1- nest))))
|
|
|
|
|
(;--Nest block inwards
|
|
|
|
|
(looking-at pascal-end-block-re)
|
1994-03-02 19:41:24 +00:00
|
|
|
|
(if (and (looking-at "end\\s ")
|
|
|
|
|
elsed (not complete))
|
|
|
|
|
(throw 'nesting 'block))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(if (= nest 0)
|
|
|
|
|
(setq funccnt (1+ funccnt)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(setq complete t
|
|
|
|
|
nest (1+ nest)))
|
|
|
|
|
(;--Defun (or parameter list)
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(and (looking-at pascal-defun-re)
|
|
|
|
|
(progn (setq funccnt (1- funccnt)
|
|
|
|
|
did-func t)
|
|
|
|
|
(or (bolp) (< funccnt 0))))
|
|
|
|
|
;; Prevent searching whole buffer
|
|
|
|
|
(if (and (bolp) (>= funccnt 0))
|
|
|
|
|
(throw 'nesting 'progbeg))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (= 0 par)
|
|
|
|
|
(throw 'nesting 'defun)
|
|
|
|
|
(setq par 0)
|
|
|
|
|
(let ((n 0))
|
|
|
|
|
(while (re-search-forward
|
|
|
|
|
"\\(\\<record\\>\\)\\|\\<end\\>"
|
|
|
|
|
oldpos t)
|
|
|
|
|
(if (match-end 1)
|
|
|
|
|
(setq n (1+ n)) (setq n (1- n))))
|
|
|
|
|
(if (> n 0)
|
|
|
|
|
(throw 'nesting 'declaration)
|
|
|
|
|
(throw 'nesting 'paramlist)))))
|
|
|
|
|
(;--Declaration part
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(and (looking-at pascal-declaration-re)
|
|
|
|
|
(not did-func)
|
|
|
|
|
(= funccnt 0))
|
1994-03-02 19:41:24 +00:00
|
|
|
|
(if (save-excursion
|
|
|
|
|
(goto-char oldpos)
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(looking-at "^[ \t]*$"))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(throw 'nesting 'unknown)
|
|
|
|
|
(throw 'nesting 'declaration)))
|
|
|
|
|
(;--If, else or while statement
|
|
|
|
|
(and (not complete)
|
|
|
|
|
(looking-at pascal-sub-block-re))
|
|
|
|
|
(throw 'nesting 'block))
|
|
|
|
|
(;--Found complete statement
|
|
|
|
|
(save-excursion (forward-sexp 1)
|
|
|
|
|
(= (following-char) ?\;))
|
|
|
|
|
(setq complete t))
|
|
|
|
|
)))))
|
1995-01-17 20:53:31 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Return type of block and indent level.
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(if (> par 0) ; Unclosed Parenthesis
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(list 'contexp par)
|
|
|
|
|
(list type (pascal-indent-level))))))
|
|
|
|
|
|
|
|
|
|
(defun pascal-indent-level ()
|
|
|
|
|
"Return the indent-level the current statement has.
|
|
|
|
|
Do not count labels, case-statements or records."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (looking-at "[ \t]*[0-9a-zA-Z]+[ \t]*:[^=]")
|
|
|
|
|
(search-forward ":" nil t)
|
|
|
|
|
(if (looking-at ".*=[ \t]*record\\>")
|
|
|
|
|
(search-forward "=" nil t)))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(current-column)))
|
|
|
|
|
|
2000-05-18 18:38:09 +00:00
|
|
|
|
(defun pascal-indent-comment ()
|
|
|
|
|
"Return indent for current comment."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-backward "\\((\\*\\)\\|{" nil t)
|
|
|
|
|
(if (match-beginning 1)
|
|
|
|
|
(1+ (current-column))
|
|
|
|
|
(current-column))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-indent-case ()
|
|
|
|
|
"Indent within case statements."
|
1996-05-13 16:25:13 +00:00
|
|
|
|
(let ((savepos (point-marker))
|
|
|
|
|
(end (prog2
|
1994-03-12 06:29:57 +00:00
|
|
|
|
(end-of-line)
|
|
|
|
|
(point-marker)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(re-search-backward "\\<case\\>" nil t)))
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(beg (point))
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(pascal--extra-indent 0))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Get right indent
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(while (< (point) end)
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(if (re-search-forward
|
1994-03-12 06:29:57 +00:00
|
|
|
|
"^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
|
|
|
|
|
(marker-position end) 'move)
|
|
|
|
|
(forward-char -1))
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(if (< (point) end)
|
1996-03-07 05:53:10 +00:00
|
|
|
|
(progn
|
|
|
|
|
(delete-horizontal-space)
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(if (> (current-column) pascal--extra-indent)
|
|
|
|
|
(setq pascal--extra-indent (current-column)))
|
1996-03-07 05:53:10 +00:00
|
|
|
|
(pascal-end-of-statement))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(goto-char beg)
|
|
|
|
|
;; Indent all case statements
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(while (< (point) end)
|
1994-03-12 06:29:57 +00:00
|
|
|
|
(if (re-search-forward
|
1995-01-17 20:53:31 +00:00
|
|
|
|
"^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
|
1994-03-12 06:29:57 +00:00
|
|
|
|
(marker-position end) 'move)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(forward-char -1))
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(indent-to (1+ pascal--extra-indent))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (/= (following-char) ?:)
|
|
|
|
|
()
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(delete-horizontal-space)
|
1994-09-03 03:34:55 +00:00
|
|
|
|
(insert " "))
|
|
|
|
|
(pascal-end-of-statement))
|
1996-05-13 16:25:13 +00:00
|
|
|
|
(goto-char savepos)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-indent-paramlist (&optional arg)
|
|
|
|
|
"Indent current line in parameterlist.
|
|
|
|
|
If optional arg is non-nil, just return the
|
|
|
|
|
indent of the current line in parameterlist."
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(save-excursion
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(let* ((oldpos (point))
|
|
|
|
|
(stpos (progn (goto-char (scan-lists (point) -1 1)) (point)))
|
|
|
|
|
(stcol (1+ (current-column)))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(edpos (progn (pascal-declaration-end)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(search-backward ")" (point-at-bol) t)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(point)))
|
|
|
|
|
(usevar (re-search-backward "\\<var\\>" stpos t)))
|
|
|
|
|
(if arg (progn
|
|
|
|
|
;; If arg, just return indent
|
|
|
|
|
(goto-char oldpos)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(if (or (not usevar) (looking-at "[ \t]*var\\>"))
|
|
|
|
|
stcol (+ 4 stcol)))
|
|
|
|
|
(goto-char stpos)
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(if (and usevar (not (looking-at "var\\>")))
|
|
|
|
|
(indent-to (+ 4 stcol)))
|
|
|
|
|
(pascal-indent-declaration nil stpos edpos)))))
|
|
|
|
|
|
|
|
|
|
(defun pascal-indent-declaration (&optional arg start end)
|
|
|
|
|
"Indent current lines as declaration, lining up the `:'s or `='s."
|
|
|
|
|
(let ((pos (point-marker)))
|
|
|
|
|
(if (and (not (or arg start)) (not (pascal-declaration-beg)))
|
|
|
|
|
()
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
":" "="))
|
|
|
|
|
(stpos (if start start
|
|
|
|
|
(forward-word 2) (backward-word 1) (point)))
|
|
|
|
|
(edpos (set-marker (make-marker)
|
|
|
|
|
(if end end
|
|
|
|
|
(max (progn (pascal-declaration-end)
|
|
|
|
|
(point))
|
|
|
|
|
pos))))
|
2012-04-27 02:48:38 +00:00
|
|
|
|
pascal--extra-indent)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(goto-char stpos)
|
|
|
|
|
;; Indent lines in record block
|
|
|
|
|
(if arg
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(while (<= (point) edpos)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(if (looking-at "end\\>")
|
|
|
|
|
(indent-to arg)
|
|
|
|
|
(indent-to (+ arg pascal-indent-level)))
|
|
|
|
|
(forward-line 1)))
|
|
|
|
|
|
|
|
|
|
;; Do lineup
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(setq pascal--extra-indent (pascal-get-lineup-indent stpos edpos lineup))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(goto-char stpos)
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(while (and (<= (point) edpos) (not (eobp)))
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(if (search-forward lineup (point-at-eol) 'move)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(forward-char -1))
|
|
|
|
|
(delete-horizontal-space)
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(indent-to pascal--extra-indent)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (not (looking-at lineup))
|
|
|
|
|
(forward-line 1) ; No more indent if there is no : or =
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(insert " ")
|
|
|
|
|
;; Indent record block
|
|
|
|
|
(if (looking-at "record\\>")
|
|
|
|
|
(pascal-indent-declaration (current-column)))
|
|
|
|
|
(forward-line 1)))))
|
|
|
|
|
|
|
|
|
|
;; If arg - move point
|
|
|
|
|
(if arg (forward-line -1)
|
1997-08-04 19:42:32 +00:00
|
|
|
|
(goto-char pos))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
; "Return the indent level that will line up several lines within the region
|
|
|
|
|
;from b to e nicely. The lineup string is str."
|
|
|
|
|
(defun pascal-get-lineup-indent (b e str)
|
|
|
|
|
(save-excursion
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(let ((pascal--extra-indent 0)
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(reg (concat str "\\|\\(\\<record\\>\\)\\|" pascal-defun-re)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(goto-char b)
|
|
|
|
|
;; Get rightmost position
|
|
|
|
|
(while (< (point) e)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(and (re-search-forward reg (min e (point-at-eol 2)) 'move)
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(cond ((match-beginning 1)
|
|
|
|
|
;; Skip record blocks
|
|
|
|
|
(pascal-declaration-end))
|
|
|
|
|
((match-beginning 2)
|
|
|
|
|
;; We have entered a new procedure. Exit.
|
|
|
|
|
(goto-char e))
|
|
|
|
|
(t
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(skip-chars-backward " \t")
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(if (> (current-column) pascal--extra-indent)
|
|
|
|
|
(setq pascal--extra-indent (current-column)))
|
1999-07-12 16:14:13 +00:00
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(end-of-line)
|
|
|
|
|
))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; In case no lineup was found
|
2012-04-27 02:48:38 +00:00
|
|
|
|
(if (> pascal--extra-indent 0)
|
|
|
|
|
(1+ pascal--extra-indent)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; No lineup-string found
|
|
|
|
|
(goto-char b)
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(1+ (current-column))))))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Completion
|
1995-01-24 03:27:54 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defun pascal-string-diff (str1 str2)
|
|
|
|
|
"Return index of first letter where STR1 and STR2 differs."
|
|
|
|
|
(catch 'done
|
|
|
|
|
(let ((diff 0))
|
|
|
|
|
(while t
|
|
|
|
|
(if (or (> (1+ diff) (length str1))
|
|
|
|
|
(> (1+ diff) (length str2)))
|
|
|
|
|
(throw 'done diff))
|
|
|
|
|
(or (equal (aref str1 diff) (aref str2 diff))
|
|
|
|
|
(throw 'done diff))
|
|
|
|
|
(setq diff (1+ diff))))))
|
|
|
|
|
|
|
|
|
|
;; Calculate all possible completions for functions if argument is `function',
|
|
|
|
|
;; completions for procedures if argument is `procedure' or both functions and
|
|
|
|
|
;; procedures otherwise.
|
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(defun pascal-func-completion (type pascal-str)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Build regular expression for function/procedure names
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(if (string= pascal-str "")
|
|
|
|
|
(setq pascal-str "[a-zA-Z_]"))
|
|
|
|
|
(let ((pascal-str (concat (cond
|
|
|
|
|
((eq type 'procedure) "\\<\\(procedure\\)\\s +")
|
|
|
|
|
((eq type 'function) "\\<\\(function\\)\\s +")
|
|
|
|
|
(t "\\<\\(function\\|procedure\\)\\s +"))
|
|
|
|
|
"\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>"))
|
|
|
|
|
(pascal-all ())
|
|
|
|
|
match)
|
2009-12-03 01:43:23 +00:00
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(if (not (looking-at "\\<\\(function\\|procedure\\)\\>"))
|
|
|
|
|
(re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t))
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
|
|
|
|
|
;; Search through all reachable functions
|
|
|
|
|
(while (pascal-beg-of-defun)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(if (re-search-forward pascal-str (point-at-eol) t)
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(progn (setq match (buffer-substring (match-beginning 2)
|
|
|
|
|
(match-end 2)))
|
|
|
|
|
(push match pascal-all)))
|
|
|
|
|
(goto-char (match-beginning 0)))
|
|
|
|
|
|
|
|
|
|
pascal-all)))
|
|
|
|
|
|
|
|
|
|
(defun pascal-get-completion-decl (pascal-str)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Macro for searching through current declaration (var, type or const)
|
1997-08-04 19:42:32 +00:00
|
|
|
|
;; for matches of `str' and adding the occurrence to `all'
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(let ((end (save-excursion (pascal-declaration-end)
|
|
|
|
|
(point)))
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(pascal-all ())
|
1994-02-01 18:14:56 +00:00
|
|
|
|
match)
|
|
|
|
|
;; Traverse lines
|
|
|
|
|
(while (< (point) end)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(if (re-search-forward "[:=]" (point-at-eol) t)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Traverse current line
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(while (and (re-search-backward
|
|
|
|
|
(concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|"
|
1994-02-01 18:14:56 +00:00
|
|
|
|
pascal-symbol-re)
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(point-at-bol) t)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(not (match-end 1)))
|
|
|
|
|
(setq match (buffer-substring (match-beginning 0) (match-end 0)))
|
1995-01-24 03:27:54 +00:00
|
|
|
|
(if (string-match (concat "\\<" pascal-str) match)
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(push match pascal-all))))
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(if (re-search-forward "\\<record\\>" (point-at-eol) t)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-declaration-end)
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(forward-line 1)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
pascal-all))
|
|
|
|
|
|
|
|
|
|
(defun pascal-type-completion (pascal-str)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Calculate all possible completions for types."
|
|
|
|
|
(let ((start (point))
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(pascal-all ())
|
1994-02-01 18:14:56 +00:00
|
|
|
|
goon)
|
|
|
|
|
;; Search for all reachable type declarations
|
|
|
|
|
(while (or (pascal-beg-of-defun)
|
|
|
|
|
(setq goon (not goon)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if (and (< start (prog1 (save-excursion (pascal-end-of-defun)
|
|
|
|
|
(point))
|
|
|
|
|
(forward-char 1)))
|
|
|
|
|
(re-search-forward
|
1994-09-03 03:34:55 +00:00
|
|
|
|
"\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
|
1994-02-01 18:14:56 +00:00
|
|
|
|
start t)
|
|
|
|
|
(not (match-end 1)))
|
|
|
|
|
;; Check current type declaration
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(setq pascal-all
|
|
|
|
|
(nconc (pascal-get-completion-decl pascal-str)
|
|
|
|
|
pascal-all)))))
|
|
|
|
|
|
|
|
|
|
pascal-all))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(defun pascal-var-completion (prefix)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Calculate all possible completions for variables (or constants)."
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((start (point))
|
|
|
|
|
(pascal-all ())
|
|
|
|
|
goon twice)
|
|
|
|
|
;; Search for all reachable var declarations
|
|
|
|
|
(while (or (pascal-beg-of-defun)
|
|
|
|
|
(setq goon (not goon)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if (> start (prog1 (save-excursion (pascal-end-of-defun)
|
|
|
|
|
(point))))
|
|
|
|
|
() ; Declarations not reachable
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(if (search-forward "(" (point-at-eol) t)
|
2009-12-02 18:31:26 +00:00
|
|
|
|
;; Check parameterlist
|
|
|
|
|
;; FIXME: pascal-get-completion-decl doesn't understand
|
|
|
|
|
;; the var declarations in parameter lists :-(
|
|
|
|
|
(setq pascal-all
|
|
|
|
|
(nconc (pascal-get-completion-decl prefix)
|
|
|
|
|
pascal-all)))
|
|
|
|
|
(setq twice 2)
|
|
|
|
|
(while (>= (setq twice (1- twice)) 0)
|
|
|
|
|
(cond
|
|
|
|
|
((and (re-search-forward
|
|
|
|
|
(concat "\\<\\(var\\|const\\)\\>\\|"
|
|
|
|
|
"\\<\\(begin\\|function\\|procedure\\)\\>")
|
|
|
|
|
start t)
|
|
|
|
|
(not (match-end 2)))
|
|
|
|
|
;; Check var/const declarations
|
|
|
|
|
(setq pascal-all
|
|
|
|
|
(nconc (pascal-get-completion-decl prefix)
|
|
|
|
|
pascal-all)))
|
|
|
|
|
((match-end 2)
|
|
|
|
|
(setq twice 0)))))))
|
|
|
|
|
pascal-all)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pascal-keyword-completion (keyword-list pascal-str)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Give list of all possible completions of keywords in KEYWORD-LIST."
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(let ((pascal-all ()))
|
|
|
|
|
(dolist (s keyword-list)
|
|
|
|
|
(if (string-match (concat "\\<" pascal-str) s)
|
|
|
|
|
(push s pascal-all)))
|
|
|
|
|
pascal-all))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
;; Function passed to completing-read, try-completion or
|
|
|
|
|
;; all-completions to get completion on STR. If predicate is non-nil,
|
|
|
|
|
;; it must be a function to be called for every match to check if this
|
|
|
|
|
;; should really be a match. If flag is t, the function returns a list
|
|
|
|
|
;; of all possible completions. If it is nil it returns a string, the
|
|
|
|
|
;; longest possible completion, or t if STR is an exact match. If flag
|
|
|
|
|
;; is 'lambda, the function returns t if STR is an exact match, nil
|
|
|
|
|
;; otherwise.
|
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(defvar pascal-completion-cache nil)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(defun pascal-completion (pascal-str pascal-pred pascal-flag)
|
|
|
|
|
(let ((all (car pascal-completion-cache)))
|
|
|
|
|
;; Check the cache's freshness.
|
|
|
|
|
(unless (and pascal-completion-cache
|
|
|
|
|
(string-prefix-p (nth 1 pascal-completion-cache) pascal-str)
|
|
|
|
|
(eq (current-buffer) (nth 2 pascal-completion-cache))
|
|
|
|
|
(eq (field-beginning) (nth 3 pascal-completion-cache)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(let ((state (car (pascal-calculate-indent))))
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(setq all
|
|
|
|
|
;; Determine what should be completed
|
|
|
|
|
(cond
|
|
|
|
|
( ;--Within a declaration or parameterlist
|
|
|
|
|
(or (eq state 'declaration) (eq state 'paramlist)
|
|
|
|
|
(and (eq state 'defun)
|
|
|
|
|
(save-excursion
|
Replace unneeded compatibility definitions with point-at-bol, point-at-eol.
* lisp/progmodes/verilog-mode.el (verilog-get-beg-of-line)
(verilog-get-end-of-line): Remove.
(verilog-within-string, verilog-re-search-forward-substr)
(verilog-re-search-backward-substr, verilog-set-auto-endcomments)
(verilog-surelint-off, verilog-getopt-file, verilog-highlight-region):
Use point-at-bol, point-at-eol.
* lisp/progmodes/pascal.el (pascal-get-beg-of-line, pascal-get-end-of-line):
Remove.
(pascal-declaration-end, pascal-declaration-beg, pascal-within-string)
(electric-pascal-terminate-line, pascal-set-auto-comments)
(pascal-indent-paramlist, pascal-indent-declaration)
(pascal-get-lineup-indent, pascal-func-completion)
(pascal-get-completion-decl, pascal-var-completion, pascal-completion):
Use point-at-bol, point-at-eol.
* lisp/progmodes/flymake.el (flymake-line-beginning-position)
(flymake-line-end-position): Remove.
(flymake-highlight-line): Use point-at-bol, point-at-eol.
* lisp/eshell/esh-util.el (line-end-position, line-beginning-position):
Remove compat definitions.
* net/tramp/tramp-compat.el: Comment.
2010-11-07 01:50:52 +00:00
|
|
|
|
(re-search-backward ")[ \t]*:" (point-at-bol) t))))
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(if (or (eq state 'paramlist) (eq state 'defun))
|
|
|
|
|
(pascal-beg-of-defun))
|
|
|
|
|
(nconc
|
|
|
|
|
(pascal-type-completion pascal-str)
|
|
|
|
|
(pascal-keyword-completion pascal-type-keywords pascal-str)))
|
|
|
|
|
( ;--Starting a new statement
|
|
|
|
|
(and (not (eq state 'contexp))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(skip-chars-backward "a-zA-Z0-9_.")
|
|
|
|
|
(backward-sexp 1)
|
|
|
|
|
(or (looking-at pascal-nosemi-re)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
(looking-at "\\s *\\(;\\|:[^=]\\)")))))
|
|
|
|
|
(nconc
|
|
|
|
|
(pascal-var-completion pascal-str)
|
|
|
|
|
(pascal-func-completion 'procedure pascal-str)
|
|
|
|
|
(pascal-keyword-completion pascal-start-keywords pascal-str)))
|
|
|
|
|
(t ;--Anywhere else
|
|
|
|
|
(nconc
|
|
|
|
|
(pascal-var-completion pascal-str)
|
|
|
|
|
(pascal-func-completion 'function pascal-str)
|
|
|
|
|
(pascal-keyword-completion pascal-separator-keywords
|
|
|
|
|
pascal-str)))))
|
|
|
|
|
|
|
|
|
|
(setq pascal-completion-cache
|
|
|
|
|
(list all pascal-str (current-buffer) (field-beginning)))))
|
|
|
|
|
|
|
|
|
|
;; Now we have built a list of all matches. Give response to caller
|
|
|
|
|
(complete-with-action pascal-flag all pascal-str pascal-pred)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defvar pascal-last-word-numb 0)
|
|
|
|
|
(defvar pascal-last-word-shown nil)
|
|
|
|
|
(defvar pascal-last-completions nil)
|
|
|
|
|
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(defun pascal-completions-at-point ()
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))))
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(when (> e b)
|
|
|
|
|
(list b e #'pascal-completion))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
Use completion-at-point rather than completion-in-region.
* lisp/wid-edit.el: Use lexical scoping and move towards completion-at-point.
(widget-complete): Use new :completion-function property.
(widget-completions-at-point): New function.
(default): Use :completion-function instead of :complete.
(widget-default-completions): Rename from widget-default-complete, rewrite.
(widget-string-complete, widget-file-complete, widget-color-complete):
Remove functions.
(file, symbol, function, variable, coding-system, color):
* lisp/international/mule-cmds.el (default-input-method, charset)
(language-info-custom-alist):
* lisp/cus-edit.el (face): Use new property :completions.
* lisp/progmodes/pascal.el (pascal-completions-at-point): New function.
(pascal-mode): Use it.
(pascal-mode-map): Use completion-at-point.
(pascal-toggle-completions): Make obsolete.
(pascal-complete-word, pascal-show-completions):
* lisp/progmodes/octave-mod.el (octave-complete-symbol):
Redefine as obsolete alias.
* lisp/progmodes/octave-inf.el (inferior-octave-completion-at-point):
Signal absence of completion info for old Octave,
(inferior-octave-complete): Redefine as obsolete alias.
* lisp/progmodes/meta-mode.el: Use lexical-binding and completion-at-point.
(meta-completions-at-point): Rename from meta-complete-symbol and
adapt it for use on completion-at-point-functions.
(meta-common-mode): Use it.
(meta-looking-at-backward, meta-match-buffer): Remove.
(meta-complete-symbol): Redefine as obsolete alias.
(meta-common-mode-map): Use completion-at-point.
* lisp/progmodes/make-mode.el: Use lexical-binding and completion-at-point.
(makefile-mode-map): Use completion-at-point.
(makefile-completions-at-point): Rename from makefile-complete and
adapt it for use on completion-at-point-functions.
(makefile-mode): Use it.
(makefile-complete): Redefine as obsolete alias.
2011-06-20 16:02:31 +00:00
|
|
|
|
(define-obsolete-function-alias 'pascal-complete-word
|
|
|
|
|
'completion-at-point "24.1")
|
|
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'pascal-show-completions
|
|
|
|
|
'completion-help-at-point "24.1")
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun pascal-get-default-symbol ()
|
|
|
|
|
"Return symbol around current point as a string."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(buffer-substring (progn
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(skip-chars-backward "a-zA-Z0-9_")
|
|
|
|
|
(point))
|
|
|
|
|
(progn
|
|
|
|
|
(skip-chars-forward "a-zA-Z0-9_")
|
|
|
|
|
(point)))))
|
|
|
|
|
|
|
|
|
|
(defun pascal-build-defun-re (str &optional arg)
|
|
|
|
|
"Return function/procedure starting with STR as regular expression.
|
|
|
|
|
With optional second arg non-nil, STR is the complete name of the instruction."
|
|
|
|
|
(if arg
|
|
|
|
|
(concat "^\\(function\\|procedure\\)[ \t]+\\(" str "\\)\\>")
|
|
|
|
|
(concat "^\\(function\\|procedure\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
|
|
|
|
|
|
|
|
|
|
;; Function passed to completing-read, try-completion or
|
|
|
|
|
;; all-completions to get completion on any function name. If
|
|
|
|
|
;; predicate is non-nil, it must be a function to be called for every
|
|
|
|
|
;; match to check if this should really be a match. If flag is t, the
|
|
|
|
|
;; function returns a list of all possible completions. If it is nil
|
|
|
|
|
;; it returns a string, the longest possible completion, or t if STR
|
|
|
|
|
;; is an exact match. If flag is 'lambda, the function returns t if
|
|
|
|
|
;; STR is an exact match, nil otherwise.
|
|
|
|
|
|
1995-01-24 03:27:54 +00:00
|
|
|
|
(defun pascal-comp-defun (pascal-str pascal-pred pascal-flag)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(save-excursion
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(let ((pascal-all nil))
|
|
|
|
|
|
|
|
|
|
;; Build regular expression for functions
|
|
|
|
|
(let ((pascal-str (pascal-build-defun-re (if (string= pascal-str "")
|
|
|
|
|
"[a-zA-Z_]"
|
|
|
|
|
pascal-str))))
|
|
|
|
|
(goto-char (point-min))
|
2009-12-03 01:43:23 +00:00
|
|
|
|
|
2009-12-02 18:31:26 +00:00
|
|
|
|
;; Build a list of all possible completions
|
|
|
|
|
(while (re-search-forward pascal-str nil t)
|
|
|
|
|
(push (match-string 2) pascal-all)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
;; Now we have built a list of all matches. Give response to caller
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(complete-with-action pascal-flag pascal-all pascal-str pascal-pred))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-goto-defun ()
|
|
|
|
|
"Move to specified Pascal function/procedure.
|
|
|
|
|
The default is a name found in the buffer around point."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((default (pascal-get-default-symbol))
|
|
|
|
|
(default (if (pascal-comp-defun default nil 'lambda)
|
|
|
|
|
default ""))
|
2009-12-03 01:43:23 +00:00
|
|
|
|
(label
|
2012-04-26 12:43:28 +00:00
|
|
|
|
;; Do completion with default.
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(completing-read (if (not (string= default ""))
|
|
|
|
|
(concat "Label (default " default "): ")
|
|
|
|
|
"Label: ")
|
|
|
|
|
;; Complete with the defuns found in the
|
|
|
|
|
;; current-buffer.
|
2012-04-26 12:43:28 +00:00
|
|
|
|
(let ((buf (current-buffer)))
|
2009-12-02 18:31:26 +00:00
|
|
|
|
(lambda (s p a)
|
|
|
|
|
(with-current-buffer buf
|
|
|
|
|
(pascal-comp-defun s p a))))
|
|
|
|
|
nil t "")))
|
2012-04-26 12:43:28 +00:00
|
|
|
|
;; If there was no response on prompt, use default value.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(if (string= label "")
|
|
|
|
|
(setq label default))
|
2012-04-26 12:43:28 +00:00
|
|
|
|
;; Goto right place in buffer if label is not an empty string.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(or (string= label "")
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(re-search-forward (pascal-build-defun-re label t))
|
|
|
|
|
(beginning-of-line)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Pascal-outline-mode
|
|
|
|
|
;;;
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(defvar pascal-outline-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(if (fboundp 'set-keymap-name)
|
|
|
|
|
(set-keymap-name pascal-outline-map 'pascal-outline-map))
|
|
|
|
|
(define-key map "\M-\C-a" 'pascal-outline-prev-defun)
|
|
|
|
|
(define-key map "\M-\C-e" 'pascal-outline-next-defun)
|
|
|
|
|
(define-key map "\C-c\C-d" 'pascal-outline-goto-defun)
|
|
|
|
|
(define-key map "\C-c\C-s" 'pascal-show-all)
|
|
|
|
|
(define-key map "\C-c\C-h" 'pascal-hide-other-defuns)
|
|
|
|
|
map)
|
|
|
|
|
"Keymap used in Pascal Outline mode.")
|
|
|
|
|
|
2009-08-21 14:59:49 +00:00
|
|
|
|
(define-obsolete-function-alias 'pascal-outline 'pascal-outline-mode "22.1")
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(define-minor-mode pascal-outline-mode
|
1994-02-01 18:14:56 +00:00
|
|
|
|
"Outline-line minor mode for Pascal mode.
|
2012-02-08 02:12:24 +00:00
|
|
|
|
With a prefix argument ARG, enable the mode if ARG is positive,
|
|
|
|
|
and disable it otherwise. If called from Lisp, enable the mode
|
|
|
|
|
if ARG is omitted or nil.
|
|
|
|
|
|
|
|
|
|
When enabled, portions of the text being edited may be made
|
|
|
|
|
invisible. \\<pascal-outline-map>
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
Pascal Outline mode provides some additional commands.
|
|
|
|
|
|
|
|
|
|
\\[pascal-outline-prev-defun]\
|
|
|
|
|
\t- Move to previous function/procedure, hiding everything else.
|
|
|
|
|
\\[pascal-outline-next-defun]\
|
|
|
|
|
\t- Move to next function/procedure, hiding everything else.
|
|
|
|
|
\\[pascal-outline-goto-defun]\
|
|
|
|
|
\t- Goto function/procedure prompted for in minibuffer,
|
|
|
|
|
\t hide all other functions.
|
|
|
|
|
\\[pascal-show-all]\t- Show the whole buffer.
|
|
|
|
|
\\[pascal-hide-other-defuns]\
|
|
|
|
|
\t- Hide everything but the current function (function under the cursor).
|
|
|
|
|
\\[pascal-outline]\t- Leave pascal-outline-mode."
|
2005-10-10 17:14:02 +00:00
|
|
|
|
:init-value nil :lighter " Outl" :keymap pascal-outline-map
|
|
|
|
|
(add-to-invisibility-spec '(pascal . t))
|
|
|
|
|
(unless pascal-outline-mode
|
|
|
|
|
(pascal-show-all)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(defun pascal-outline-change (b e hide)
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(when (> e b)
|
|
|
|
|
;; We could try and optimize this in the case where the region is
|
|
|
|
|
;; already hidden. But I'm not sure it's worth the trouble.
|
|
|
|
|
(remove-overlays b e 'invisible 'pascal)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(when hide
|
2005-10-10 17:14:02 +00:00
|
|
|
|
(let ((ol (make-overlay b e nil t nil)))
|
|
|
|
|
(overlay-put ol 'invisible 'pascal)
|
|
|
|
|
(overlay-put ol 'evaporate t)))))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-show-all ()
|
|
|
|
|
"Show all of the text in the buffer."
|
|
|
|
|
(interactive)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change (point-min) (point-max) nil))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(defun pascal-hide-other-defuns ()
|
|
|
|
|
"Show only the current defun."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((beg (progn (if (not (looking-at "\\(function\\|procedure\\)\\>"))
|
|
|
|
|
(pascal-beg-of-defun))
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(line-beginning-position)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(end (progn (pascal-end-of-defun)
|
|
|
|
|
(backward-sexp 1)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(line-beginning-position 2)))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(opoint (point-min)))
|
2010-09-20 14:57:01 +00:00
|
|
|
|
;; BEG at BOL.
|
|
|
|
|
;; OPOINT at EOL.
|
|
|
|
|
;; END at BOL.
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
|
|
|
|
|
;; Hide all functions before current function
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(while (re-search-forward "^[ \t]*\\(function\\|procedure\\)\\>"
|
|
|
|
|
beg 'move)
|
|
|
|
|
(pascal-outline-change opoint (line-end-position 0) t)
|
|
|
|
|
(setq opoint (line-end-position))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Functions may be nested
|
|
|
|
|
(if (> (progn (pascal-end-of-defun) (point)) beg)
|
|
|
|
|
(goto-char opoint)))
|
|
|
|
|
(if (> beg opoint)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change opoint (1- beg) t))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
;; Show current function
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change (1- beg) end nil)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;; Hide nested functions
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(while (re-search-forward "^\\(function\\|procedure\\)\\>" end 'move)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(setq opoint (line-end-position))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-end-of-defun)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change opoint (line-end-position) t))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(setq opoint end)
|
|
|
|
|
|
|
|
|
|
;; Hide all function after current function
|
|
|
|
|
(while (re-search-forward "^\\(function\\|procedure\\)\\>" nil 'move)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change opoint (line-end-position 0) t)
|
|
|
|
|
(setq opoint (line-end-position))
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(pascal-end-of-defun))
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change opoint (point-max) t)
|
1994-02-01 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
;; Hide main program
|
|
|
|
|
(if (< (progn (forward-line -1) (point)) end)
|
1993-11-08 14:46:50 +00:00
|
|
|
|
(progn
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(goto-char beg)
|
|
|
|
|
(pascal-end-of-defun)
|
|
|
|
|
(backward-sexp 1)
|
2010-09-20 14:57:01 +00:00
|
|
|
|
(pascal-outline-change (line-end-position) (point-max) t))))))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
(defun pascal-outline-next-defun ()
|
|
|
|
|
"Move to next function/procedure, hiding all others."
|
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-end-of-defun)
|
|
|
|
|
(pascal-hide-other-defuns))
|
|
|
|
|
|
|
|
|
|
(defun pascal-outline-prev-defun ()
|
|
|
|
|
"Move to previous function/procedure, hiding all others."
|
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-beg-of-defun)
|
|
|
|
|
(pascal-hide-other-defuns))
|
|
|
|
|
|
|
|
|
|
(defun pascal-outline-goto-defun ()
|
|
|
|
|
"Move to specified function/procedure, hiding all others."
|
|
|
|
|
(interactive)
|
|
|
|
|
(pascal-goto-defun)
|
|
|
|
|
(pascal-hide-other-defuns))
|
1993-11-08 14:46:50 +00:00
|
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
|
(provide 'pascal)
|
|
|
|
|
|
1994-02-01 18:14:56 +00:00
|
|
|
|
;;; pascal.el ends here
|