123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512 |
- (eval-when-compile (require 'cl))
- (defgroup pascal nil
- "Major mode for editing Pascal source in Emacs."
- :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
- :group 'languages)
- (defvar pascal-mode-abbrev-table nil
- "Abbrev table in use in Pascal-mode buffers.")
- (define-abbrev-table 'pascal-mode-abbrev-table ())
- (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)
-
-
-
- (define-key map "\M-\t" 'completion-at-point)
- (define-key map "\M-?" 'completion-help-at-point)
- (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)
-
-
-
-
-
- map)
- "Keymap used in Pascal mode.")
- (defvar pascal-imenu-generic-expression
- '((nil "^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" 2))
- "Imenu expression for Pascal-mode. See `imenu-generic-expression'.")
- (defvar pascal-keywords
- '("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"
- "type" "until" "var" "while" "with"
-
- "get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write"
- "writeln"))
- (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\\)\\>")
- (defconst pascal-progbeg-re "\\<\\program\\>")
- (defconst pascal-defun-re "\\<\\(function\\|procedure\\|program\\)\\>")
- (defconst pascal-sub-block-re "\\<\\(if\\|else\\|for\\|while\\|with\\)\\>")
- (defconst pascal-noindent-re "\\<\\(begin\\|end\\|until\\|else\\)\\>")
- (defconst pascal-nosemi-re "\\<\\(begin\\|repeat\\|then\\|do\\|else\\)\\>")
- (defconst pascal-autoindent-lines-re
- "\\<\\(label\\|var\\|type\\|const\\|until\\|end\\|begin\\|repeat\\|else\\)\\>")
- (defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----")
- (defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}")
- (defvar pascal-mode-syntax-table
- (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\\ "." st)
- (modify-syntax-entry ?\( "()1" st)
- (modify-syntax-entry ?\) ")(4" st)
-
-
-
- (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)
- "Syntax table in use in Pascal-mode buffers.")
- (defconst pascal-font-lock-keywords (purecopy
- (list
- '("^[ \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)
- (cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|"
- "integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>")
- 'font-lock-type-face)
- '("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-constant-face)
- '("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-function-name-face)
- (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]+\\)?"
- 1 font-lock-keyword-face)
- '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
- 2 font-lock-keyword-face t)))
- "Additional expressions to highlight in Pascal mode.")
- (put 'pascal-mode 'font-lock-defaults '(pascal-font-lock-keywords nil t))
- (defcustom pascal-indent-level 3
- "*Indentation of Pascal statements with respect to containing block."
- :type 'integer
- :group 'pascal)
- (defcustom pascal-case-indent 2
- "*Indentation for case statements."
- :type 'integer
- :group 'pascal)
- (defcustom pascal-auto-newline nil
- "*Non-nil means automatically insert newlines in certain cases.
- These include after semicolons and after the punctuation mark after an `end'."
- :type 'boolean
- :group 'pascal)
- (defcustom pascal-indent-nested-functions t
- "*Non-nil means nested functions are indented."
- :type 'boolean
- :group 'pascal)
- (defcustom pascal-tab-always-indent t
- "*Non-nil means TAB in Pascal mode should always reindent the current line.
- 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
- "*Non-nil means automatically insert comments after certain `end's.
- 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)
- "*List of contexts where auto lineup of :'s or ='s should be done.
- Elements can be of type: 'paramlist', 'declaration' or 'case', which will
- do auto lineup in parameterlist, declarations or case-statements
- respectively. The word 'all' will do all lineups. '(case paramlist) for
- instance will do lineup in case-statements and parameterlist, while '(all)
- will do all lineups."
- :type '(set :extra-offset 8
- (const :tag "Everything" all)
- (const :tag "Parameter lists" paramlist)
- (const :tag "Declarations" declaration)
- (const :tag "Case statements" case))
- :group 'pascal)
- (defvar pascal-toggle-completions nil
- "*Non-nil meant \\<pascal-mode-map>\\[pascal-complete-word] would try all possible completions one by one.
- Repeated use of \\[pascal-complete-word] would show you all of them.
- Normally, when there is more than one possible completion,
- it displays a list of all possible completions.")
- (make-obsolete-variable 'pascal-toggle-completions
- 'completion-cycle-threshold "24.1")
- (defcustom pascal-type-keywords
- '("array" "file" "packed" "char" "integer" "real" "string" "record")
- "*Keywords for types used when completing a word in a declaration or parmlist.
- 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)
- (defcustom pascal-start-keywords
- '("begin" "end" "function" "procedure" "repeat" "until" "while"
- "read" "readln" "reset" "rewrite" "write" "writeln")
- "*Keywords to complete when standing at the first word of a statement.
- These are keywords such as begin, repeat, until, readln.
- The procedures and variables 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)
- (defcustom pascal-separator-keywords
- '("downto" "else" "mod" "div" "then")
- "*Keywords to complete when NOT standing at the first word of a statement.
- 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)
- (defun pascal-declaration-end ()
- (let ((nest 1))
- (while (and (> nest 0)
- (re-search-forward
- "[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)"
- (point-at-eol 2) t))
- (cond ((match-beginning 1) (setq nest (1+ nest)))
- ((match-beginning 2) (setq nest (1- nest)))
- ((looking-at "[^(\n]+)") (setq nest 0))))))
- (defun pascal-declaration-beg ()
- (let ((nest 1))
- (while (and (> nest 0)
- (re-search-backward "[:=]\\|\\<\\(type\\|var\\|label\\|const\\)\\>\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)" (point-at-bol 0) t))
- (cond ((match-beginning 1) (setq nest 0))
- ((match-beginning 2) (setq nest (1- nest)))
- ((match-beginning 3) (setq nest (1+ nest)))))
- (= nest 0)))
- (defsubst pascal-within-string ()
- (nth 3 (parse-partial-sexp (point-at-bol) (point))))
- (define-derived-mode pascal-mode prog-mode "Pascal"
- "Major mode for editing Pascal code. \\<pascal-mode-map>
- TAB indents for Pascal code. Delete converts tabs to spaces as it moves back.
- \\[completion-at-point] completes the word around current point with respect \
- to position in code
- \\[completion-help-at-point] shows all possible completions at this point.
- 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.
- \\[pascal-outline-mode]\t- Enter `pascal-outline-mode'.
- Variables controlling indentation/edit style:
- `pascal-indent-level' (default 3)
- Indentation of Pascal statements with respect to containing block.
- `pascal-case-indent' (default 2)
- Indentation for case statements.
- `pascal-auto-newline' (default nil)
- Non-nil means automatically newline after semicolons and the punctuation
- mark after an end.
- `pascal-indent-nested-functions' (default t)
- Non-nil means nested functions are indented.
- `pascal-tab-always-indent' (default t)
- 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.
- `pascal-auto-endcomments' (default t)
- 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.
- `pascal-auto-lineup' (default t)
- List of contexts where auto lineup of :'s or ='s should be done.
- See also the user variables `pascal-type-keywords', `pascal-start-keywords' and
- `pascal-separator-keywords'.
- Turning on Pascal mode calls the value of the variable pascal-mode-hook with
- no args, if that value is non-nil."
- (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) "}")
- (add-hook 'completion-at-point-functions 'pascal-completions-at-point nil t)
-
- (set (make-local-variable 'font-lock-defaults)
- '(pascal-font-lock-keywords nil t))
-
- (set (make-local-variable 'imenu-generic-expression)
- pascal-imenu-generic-expression)
- (set (make-local-variable 'imenu-case-fold-search) t)
-
- (add-to-invisibility-spec '(pascal . t)))
- (defun electric-pascal-terminate-line ()
- "Terminate line and indent next line."
- (interactive)
-
- (save-excursion
- (beginning-of-line)
- (skip-chars-forward " \t")
- (if (looking-at pascal-autoindent-lines-re)
- (pascal-indent-line)))
- (delete-horizontal-space)
- (newline)
-
- (pascal-indent-line)
-
- (if pascal-auto-endcomments
- (pascal-set-auto-comments))
-
- (let ((setstar nil))
- (save-excursion
- (forward-line -1)
- (skip-chars-forward " \t")
- (cond ((looking-at "\\*[ \t]+)")
-
- (forward-char 1)
- (delete-horizontal-space))
- ((and (looking-at "(\\*\\|\\*[^)]")
- (not (save-excursion (search-forward "*)" (point-at-eol) t))))
- (setq setstar t))))
-
- (if (null setstar)
- (pascal-indent-line)
- (insert "* "))))
- (defun electric-pascal-semi-or-dot ()
- "Insert `;' or `.' character and reindent the line."
- (interactive)
- (insert last-command-event)
- (save-excursion
- (beginning-of-line)
- (pascal-indent-line))
- (if pascal-auto-newline
- (electric-pascal-terminate-line)))
- (defun electric-pascal-colon ()
- "Insert `:' and do all indentations except line indent on this line."
- (interactive)
- (insert last-command-event)
-
- (if (pascal-within-string)
- ()
- (save-excursion
- (beginning-of-line)
- (pascal-indent-line))
- (let ((pascal-tab-always-indent nil))
- (pascal-indent-command))))
- (defun electric-pascal-equal ()
- "Insert `=', and do indentation if within type declaration."
- (interactive)
- (insert last-command-event)
- (if (eq (car (pascal-calculate-indent)) 'declaration)
- (let ((pascal-tab-always-indent nil))
- (pascal-indent-command))))
- (defun electric-pascal-hash ()
- "Insert `#', and indent to column 0 if this is a CPP directive."
- (interactive)
- (insert last-command-event)
- (if (save-excursion (beginning-of-line) (looking-at "^[ \t]*#"))
- (save-excursion (beginning-of-line)
- (delete-horizontal-space))))
- (defun electric-pascal-tab ()
- "Function called when TAB is pressed in Pascal mode."
- (interactive)
-
- (if (or (pascal-within-string)
- (and (not (bolp))
- (save-excursion (beginning-of-line) (eq (following-char) ?#))))
- (insert "\t")
-
- (if pascal-tab-always-indent
- (save-excursion
- (beginning-of-line)
- (pascal-indent-line))
- (if (save-excursion
- (skip-chars-backward " \t")
- (bolp))
- (pascal-indent-line)
- (insert "\t")))
- (pascal-indent-command)))
- (defun pascal-insert-block ()
- "Insert Pascal begin ... end; block in the code with right indentation."
- (interactive)
- (insert "begin")
- (electric-pascal-terminate-line)
- (save-excursion
- (newline)
- (insert "end;")
- (beginning-of-line)
- (pascal-indent-line)))
- (defun pascal-star-comment ()
- "Insert Pascal star comment at point."
- (interactive)
- (pascal-indent-line)
- (insert "(*")
- (electric-pascal-terminate-line)
- (save-excursion
- (electric-pascal-terminate-line)
- (delete-horizontal-space)
- (insert ")"))
- (insert " "))
- (defun pascal-mark-defun ()
- "Mark the current pascal function (or procedure).
- This puts the mark at the end, and point at the beginning."
- (interactive)
- (push-mark (point))
- (pascal-end-of-defun)
- (push-mark (point))
- (pascal-beg-of-defun)
- (when (featurep 'xemacs)
- (zmacs-activate-region)))
- (defun pascal-comment-area (start end)
- "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."
- (interactive "r")
- (save-excursion
-
- (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))
- (insert pascal-exclude-str-end)
- (setq end (point))
- (newline)
- (goto-char start)
- (beginning-of-line)
- (insert pascal-exclude-str-start)
- (newline)
-
- (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 ()
- "Uncomment a commented area; change deformed comments back to normal.
- This command does nothing if the pointer is not in a commented
- area. See also `pascal-comment-area'."
- (interactive)
- (save-excursion
- (let ((start (point))
- (end (point)))
-
- (save-excursion
- (setq start (progn (search-backward pascal-exclude-str-start nil t)
- (point)))
- (setq end (progn (search-forward pascal-exclude-str-end nil t)
- (point))))
-
- (if (or (equal start (point)) (<= end (point)))
- (message "Not standing within commented area.")
- (progn
-
- (goto-char end)
- (beginning-of-line)
- (let ((pos (point)))
- (end-of-line)
- (delete-region pos (1+ (point))))
-
- (save-excursion
- (while (re-search-backward "!{" start t)
- (replace-match "}" t t)))
- (save-excursion
- (while (re-search-backward "!(\\*" start t)
- (replace-match "*)" t t)))
-
- (goto-char start)
- (beginning-of-line)
- (let ((pos (point)))
- (end-of-line)
- (delete-region pos (1+ (point)))))))))
- (defun pascal-beg-of-defun ()
- "Move backward to the beginning of the current function or procedure."
- (interactive)
- (catch 'found
- (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))
- (forward-sexp 1))
- (let ((nest 0) (max -1) (func 0)
- (reg (concat pascal-beg-block-re "\\|"
- 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)))
- ())
- ((match-end 1)
- (if (and (looking-at "\\<record\\>") (>= max 0))
- (setq func (1- func)))
- (setq nest (1+ nest)
- max (max nest max)))
- ((match-end 2)
- (if (and (= nest max) (>= max 0))
- (setq func (1+ func)))
- (setq nest (1- nest)))
- ((match-end 3)
- (if (= 0 func)
- (throw 'found t)
- (setq func (1- func)))))))
- nil))
- (defun pascal-end-of-defun ()
- "Move forward to the end of the current function or procedure."
- (interactive)
- (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)
- (reg (concat pascal-beg-block-re "\\|"
- 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)))
- ())
- ((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))
- (defun pascal-end-of-statement ()
- "Move forward to end of current statement."
- (interactive)
- (let ((parse-sexp-ignore-comments t)
- (nest 0) pos
- (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)
-
- (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)
-
- (catch 'found
- (while t
- (re-search-forward regexp nil 'move)
- (setq nest (if (match-end 1)
- (1+ nest)
- (1- nest)))
- (cond ((eobp)
- (throw 'found (point)))
- ((= 0 nest)
- (throw 'found (pascal-end-of-statement))))))
- pos)))
- (defun pascal-downcase-keywords ()
- "Downcase all Pascal keywords in the buffer."
- (interactive)
- (pascal-change-keywords 'downcase-word))
- (defun pascal-upcase-keywords ()
- "Upcase all Pascal keywords in the buffer."
- (interactive)
- (pascal-change-keywords 'upcase-word))
- (defun pascal-capitalize-keywords ()
- "Capitalize all Pascal keywords in the buffer."
- (interactive)
- (pascal-change-keywords 'capitalize-word))
- (defun pascal-change-keywords (change-word)
- (save-excursion
- (let ((keyword-re (concat "\\<\\("
- (mapconcat 'identity pascal-keywords "\\|")
- "\\)\\>")))
- (goto-char (point-min))
- (while (re-search-forward keyword-re nil t)
- (funcall change-word -1)))))
- (defun pascal-set-auto-comments ()
- "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."
- (save-excursion
- (forward-line -1)
- (skip-chars-forward " \t")
- (if (and (looking-at "\\<end;")
- (not (save-excursion
- (end-of-line)
- (search-backward "{" (point-at-bol) t))))
- (let ((type (car (pascal-calculate-indent))))
- (if (eq type 'declaration)
- ()
- (if (eq type 'case)
-
- (progn
- (end-of-line)
- (delete-horizontal-space)
- (insert " { case }"))
- (let ((nest 1))
-
- (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 " }"))))))))))
- (defconst pascal-indent-alist
- '((block . (+ ind pascal-indent-level))
- (case . (+ ind pascal-case-indent))
- (caseblock . ind) (cpp . 0)
- (declaration . (+ ind pascal-indent-level))
- (paramlist . (pascal-indent-paramlist t))
- ( . (pascal-indent-comment))
- (defun . ind) (contexp . ind)
- (unknown . ind) (string . 0) (progbeg . 0)))
- (defun pascal-indent-command ()
- "Indent for special part of code."
- (let* ((indent-str (pascal-calculate-indent))
- (type (car indent-str)))
- (cond ((and (eq type 'paramlist)
- (or (memq 'all pascal-auto-lineup)
- (memq 'paramlist pascal-auto-lineup)))
- (pascal-indent-paramlist)
- (pascal-indent-paramlist))
- ((and (eq type 'declaration)
- (or (memq 'all pascal-auto-lineup)
- (memq 'declaration pascal-auto-lineup)))
- (pascal-indent-declaration))
- ((and (eq type 'case) (not (looking-at "^[ \t]*$"))
- (or (memq 'all pascal-auto-lineup)
- (memq 'case pascal-auto-lineup)))
- (pascal-indent-case)))
- (if (looking-at "[ \t]+$")
- (skip-chars-forward " \t"))))
- (defvar ind)
- (defun pascal-indent-line ()
- "Indent current line as a Pascal statement."
- (let* ((indent-str (pascal-calculate-indent))
- (type (car indent-str))
- (ind (car (cdr indent-str))))
-
- (if (and (looking-at "^[0-9a-zA-Z]+[ \t]*:[^=]")
- (not (eq type 'declaration)))
- (search-forward ":" nil t))
- (delete-horizontal-space)
- (cond (
- (or (and (eq type 'declaration) (looking-at pascal-declaration-re))
- (eq type 'cpp))
- ())
- (
- (looking-at pascal-noindent-re)
- (indent-to ind))
- (
- (looking-at pascal-defun-re)
- (if (and pascal-indent-nested-functions
- (eq type 'defun))
- (indent-to (+ ind pascal-indent-level))
- (indent-to ind)))
- (
- (indent-to (eval (cdr (assoc type pascal-indent-alist))))
- ))))
- (defun pascal-calculate-indent ()
- "Calculate the indent of the current Pascal line.
- Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
- (save-excursion
- (let* ((parse-sexp-ignore-comments t)
- (oldpos (point))
- (state (save-excursion (parse-partial-sexp (point-min) (point))))
- (nest 0) (par 0) (complete (looking-at "[ \t]*end\\>"))
- (elsed (looking-at "[ \t]*else\\>")) (funccnt 0)
- (did-func (looking-at "[ \t]*\\(procedure\\|function\\)\\>"))
- (type (catch 'nesting
-
- (cond ((nth 3 state) (throw 'nesting 'string))
- ((nth 4 state) (throw 'nesting 'comment))
- ((> (car state) 0)
- (goto-char (scan-lists (point) -1 (car state)))
- (setq par (1+ (current-column))))
- ((save-excursion (beginning-of-line)
- (eq (following-char) ?#))
- (throw 'nesting 'cpp)))
-
- (while t
- (backward-sexp 1)
- (cond (
- (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))
- (
- (looking-at pascal-progbeg-re)
- (throw 'nesting 'progbeg))
- (
- (bobp)
- (throw 'nesting 'progbeg))
- (
- (looking-at pascal-beg-block-re)
- (if (= nest 0)
- (cond ((looking-at "case\\>")
- (throw 'nesting 'case))
- ((looking-at "record\\>")
- (throw 'nesting 'declaration))
- (t (throw 'nesting 'block)))
- (if (and (looking-at "record\\>") (= nest 1))
- (setq funccnt (1- funccnt)))
- (setq nest (1- nest))))
- (
- (looking-at pascal-end-block-re)
- (if (and (looking-at "end\\s ")
- elsed (not complete))
- (throw 'nesting 'block))
- (if (= nest 0)
- (setq funccnt (1+ funccnt)))
- (setq complete t
- nest (1+ nest)))
- (
- (and (looking-at pascal-defun-re)
- (progn (setq funccnt (1- funccnt)
- did-func t)
- (or (bolp) (< funccnt 0))))
-
- (if (and (bolp) (>= funccnt 0))
- (throw 'nesting 'progbeg))
- (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)))))
- (
- (and (looking-at pascal-declaration-re)
- (not did-func)
- (= funccnt 0))
- (if (save-excursion
- (goto-char oldpos)
- (forward-line -1)
- (looking-at "^[ \t]*$"))
- (throw 'nesting 'unknown)
- (throw 'nesting 'declaration)))
- (
- (and (not complete)
- (looking-at pascal-sub-block-re))
- (throw 'nesting 'block))
- (
- (save-excursion (forward-sexp 1)
- (= (following-char) ?\
- (setq complete t))
- )))))
-
- (if (> par 0)
- (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."
- (save-excursion
- (beginning-of-line)
- (if (looking-at "[ \t]*[0-9a-zA-Z]+[ \t]*:[^=]")
- (search-forward ":" nil t)
- (if (looking-at ".*=[ \t]*record\\>")
- (search-forward "=" nil t)))
- (skip-chars-forward " \t")
- (current-column)))
- (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))))
- (defun pascal-indent-case ()
- "Indent within case statements."
- (let ((savepos (point-marker))
- (end (prog2
- (end-of-line)
- (point-marker)
- (re-search-backward "\\<case\\>" nil t)))
- (beg (point))
- (ind 0))
-
- (while (< (point) end)
- (if (re-search-forward
- "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
- (marker-position end) 'move)
- (forward-char -1))
- (if (< (point) end)
- (progn
- (delete-horizontal-space)
- (if (> (current-column) ind)
- (setq ind (current-column)))
- (pascal-end-of-statement))))
- (goto-char beg)
-
- (while (< (point) end)
- (if (re-search-forward
- "^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
- (marker-position end) 'move)
- (forward-char -1))
- (indent-to (1+ ind))
- (if (/= (following-char) ?:)
- ()
- (forward-char 1)
- (delete-horizontal-space)
- (insert " "))
- (pascal-end-of-statement))
- (goto-char savepos)))
- (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."
- (save-excursion
- (let* ((oldpos (point))
- (stpos (progn (goto-char (scan-lists (point) -1 1)) (point)))
- (stcol (1+ (current-column)))
- (edpos (progn (pascal-declaration-end)
- (search-backward ")" (point-at-bol) t)
- (point)))
- (usevar (re-search-backward "\\<var\\>" stpos t)))
- (if arg (progn
-
- (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)))
- ()
- (let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start)
- ":" "="))
- (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))))
- ind)
- (goto-char stpos)
-
- (if arg
- (while (<= (point) edpos)
- (beginning-of-line)
- (delete-horizontal-space)
- (if (looking-at "end\\>")
- (indent-to arg)
- (indent-to (+ arg pascal-indent-level)))
- (forward-line 1)))
-
- (setq ind (pascal-get-lineup-indent stpos edpos lineup))
- (goto-char stpos)
- (while (and (<= (point) edpos) (not (eobp)))
- (if (search-forward lineup (point-at-eol) 'move)
- (forward-char -1))
- (delete-horizontal-space)
- (indent-to ind)
- (if (not (looking-at lineup))
- (forward-line 1)
- (forward-char 1)
- (delete-horizontal-space)
- (insert " ")
-
- (if (looking-at "record\\>")
- (pascal-indent-declaration (current-column)))
- (forward-line 1)))))
-
- (if arg (forward-line -1)
- (goto-char pos))))
- (defun pascal-get-lineup-indent (b e str)
- (save-excursion
- (let ((ind 0)
- (reg (concat str "\\|\\(\\<record\\>\\)\\|" pascal-defun-re)))
- (goto-char b)
-
- (while (< (point) e)
- (and (re-search-forward reg (min e (point-at-eol 2)) 'move)
- (cond ((match-beginning 1)
-
- (pascal-declaration-end))
- ((match-beginning 2)
-
- (goto-char e))
- (t
- (goto-char (match-beginning 0))
- (skip-chars-backward " \t")
- (if (> (current-column) ind)
- (setq ind (current-column)))
- (goto-char (match-end 0))
- (end-of-line)
- ))))
-
- (if (> ind 0)
- (1+ ind)
-
- (goto-char b)
- (end-of-line)
- (skip-chars-backward " \t")
- (1+ (current-column))))))
- (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))))))
- (defun pascal-func-completion (type pascal-str)
-
- (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)
- (if (not (looking-at "\\<\\(function\\|procedure\\)\\>"))
- (re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t))
- (forward-char 1)
-
- (while (pascal-beg-of-defun)
- (if (re-search-forward pascal-str (point-at-eol) t)
- (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)
-
-
- (let ((end (save-excursion (pascal-declaration-end)
- (point)))
- (pascal-all ())
- match)
-
- (while (< (point) end)
- (if (re-search-forward "[:=]" (point-at-eol) t)
-
- (while (and (re-search-backward
- (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|"
- pascal-symbol-re)
- (point-at-bol) t)
- (not (match-end 1)))
- (setq match (buffer-substring (match-beginning 0) (match-end 0)))
- (if (string-match (concat "\\<" pascal-str) match)
- (push match pascal-all))))
- (if (re-search-forward "\\<record\\>" (point-at-eol) t)
- (pascal-declaration-end)
- (forward-line 1)))
- pascal-all))
- (defun pascal-type-completion (pascal-str)
- "Calculate all possible completions for types."
- (let ((start (point))
- (pascal-all ())
- goon)
-
- (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
- "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
- start t)
- (not (match-end 1)))
-
- (setq pascal-all
- (nconc (pascal-get-completion-decl pascal-str)
- pascal-all)))))
- pascal-all))
- (defun pascal-var-completion (prefix)
- "Calculate all possible completions for variables (or constants)."
- (save-excursion
- (let ((start (point))
- (pascal-all ())
- goon twice)
-
- (while (or (pascal-beg-of-defun)
- (setq goon (not goon)))
- (save-excursion
- (if (> start (prog1 (save-excursion (pascal-end-of-defun)
- (point))))
- ()
- (if (search-forward "(" (point-at-eol) t)
-
-
-
- (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)))
-
- (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)
- "Give list of all possible completions of keywords in KEYWORD-LIST."
- (let ((pascal-all ()))
- (dolist (s keyword-list)
- (if (string-match (concat "\\<" pascal-str) s)
- (push s pascal-all)))
- pascal-all))
- (defvar pascal-completion-cache nil)
- (defun pascal-completion (pascal-str pascal-pred pascal-flag)
- (let ((all (car pascal-completion-cache)))
-
- (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)))
- (let ((state (car (pascal-calculate-indent))))
- (setq all
-
- (cond
- (
- (or (eq state 'declaration) (eq state 'paramlist)
- (and (eq state 'defun)
- (save-excursion
- (re-search-backward ")[ \t]*:" (point-at-bol) t))))
- (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)))
- (
- (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
- (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)))))
-
- (complete-with-action pascal-flag all pascal-str pascal-pred)))
- (defvar pascal-last-word-numb 0)
- (defvar pascal-last-word-shown nil)
- (defvar pascal-last-completions nil)
- (defun pascal-completions-at-point ()
- (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
- (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))))
- (when (> e b)
- (list b e #'pascal-completion))))
- (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")
- (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_]*\\)\\>")))
- (defun pascal-comp-defun (pascal-str pascal-pred pascal-flag)
- (save-excursion
- (let ((pascal-all nil))
-
- (let ((pascal-str (pascal-build-defun-re (if (string= pascal-str "")
- "[a-zA-Z_]"
- pascal-str))))
- (goto-char (point-min))
-
- (while (re-search-forward pascal-str nil t)
- (push (match-string 2) pascal-all)))
-
- (complete-with-action pascal-flag pascal-all pascal-str pascal-pred))))
- (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 ""))
- (label
-
- (completing-read (if (not (string= default ""))
- (concat "Label (default " default "): ")
- "Label: ")
-
-
- (lexical-let ((buf (current-buffer)))
- (lambda (s p a)
- (with-current-buffer buf
- (pascal-comp-defun s p a))))
- nil t "")))
-
- (if (string= label "")
- (setq label default))
-
- (or (string= label "")
- (progn
- (goto-char (point-min))
- (re-search-forward (pascal-build-defun-re label t))
- (beginning-of-line)))))
- (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.")
- (define-obsolete-function-alias 'pascal-outline 'pascal-outline-mode "22.1")
- (define-minor-mode pascal-outline-mode
- "Outline-line minor mode for Pascal mode.
- 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>
- 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."
- :init-value nil :lighter " Outl" :keymap pascal-outline-map
- (add-to-invisibility-spec '(pascal . t))
- (unless pascal-outline-mode
- (pascal-show-all)))
- (defun pascal-outline-change (b e hide)
- (when (> e b)
-
-
- (remove-overlays b e 'invisible 'pascal)
- (when hide
- (let ((ol (make-overlay b e nil t nil)))
- (overlay-put ol 'invisible 'pascal)
- (overlay-put ol 'evaporate t)))))
- (defun pascal-show-all ()
- "Show all of the text in the buffer."
- (interactive)
- (pascal-outline-change (point-min) (point-max) nil))
- (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))
- (line-beginning-position)))
- (end (progn (pascal-end-of-defun)
- (backward-sexp 1)
- (line-beginning-position 2)))
- (opoint (point-min)))
-
-
-
- (goto-char (point-min))
-
- (while (re-search-forward "^[ \t]*\\(function\\|procedure\\)\\>"
- beg 'move)
- (pascal-outline-change opoint (line-end-position 0) t)
- (setq opoint (line-end-position))
-
- (if (> (progn (pascal-end-of-defun) (point)) beg)
- (goto-char opoint)))
- (if (> beg opoint)
- (pascal-outline-change opoint (1- beg) t))
-
- (pascal-outline-change (1- beg) end nil)
-
- (forward-char 1)
- (while (re-search-forward "^\\(function\\|procedure\\)\\>" end 'move)
- (setq opoint (line-end-position))
- (pascal-end-of-defun)
- (pascal-outline-change opoint (line-end-position) t))
- (goto-char end)
- (setq opoint end)
-
- (while (re-search-forward "^\\(function\\|procedure\\)\\>" nil 'move)
- (pascal-outline-change opoint (line-end-position 0) t)
- (setq opoint (line-end-position))
- (pascal-end-of-defun))
- (pascal-outline-change opoint (point-max) t)
-
- (if (< (progn (forward-line -1) (point)) end)
- (progn
- (goto-char beg)
- (pascal-end-of-defun)
- (backward-sexp 1)
- (pascal-outline-change (line-end-position) (point-max) t))))))
- (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))
- (provide 'pascal)
|