/[emacs]/emacs/lisp/progmodes/pascal.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/pascal.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38 by eliz, Tue Feb 12 17:37:02 2002 UTC revision 1.38.4.1 by miles, Fri Apr 4 06:20:36 2003 UTC
# Line 43  Line 43 
43  ;;       pascal-auto-endcomments   t  ;;       pascal-auto-endcomments   t
44  ;;       pascal-auto-lineup        '(all)  ;;       pascal-auto-lineup        '(all)
45  ;;       pascal-toggle-completions nil  ;;       pascal-toggle-completions nil
46  ;;       pascal-type-keywords      '("array" "file" "packed" "char"  ;;       pascal-type-keywords      '("array" "file" "packed" "char"
47  ;;                                   "integer" "real" "string" "record")  ;;                                   "integer" "real" "string" "record")
48  ;;       pascal-start-keywords     '("begin" "end" "function" "procedure"  ;;       pascal-start-keywords     '("begin" "end" "function" "procedure"
49  ;;                                   "repeat" "until" "while" "read" "readln"  ;;                                   "repeat" "until" "while" "read" "readln"
# Line 104  Line 104 
104    "Imenu expression for Pascal-mode.  See `imenu-generic-expression'.")    "Imenu expression for Pascal-mode.  See `imenu-generic-expression'.")
105    
106  (defvar pascal-keywords  (defvar pascal-keywords
107    '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end"    '("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end"
108      "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of"      "file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of"
109      "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to"      "or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to"
110      "type" "until" "var" "while" "with"      "type" "until" "var" "while" "with"
111      ;; The following are not standard in pascal, but widely used.      ;; The following are not standard in pascal, but widely used.
112      "get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write"      "get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write"
# Line 138  Line 138 
138      ()      ()
139    (setq pascal-mode-syntax-table (make-syntax-table))    (setq pascal-mode-syntax-table (make-syntax-table))
140    (modify-syntax-entry ?\\ "."   pascal-mode-syntax-table)    (modify-syntax-entry ?\\ "."   pascal-mode-syntax-table)
141    (modify-syntax-entry ?( "()1"  pascal-mode-syntax-table)      (modify-syntax-entry ?( "()1"  pascal-mode-syntax-table)
142    (modify-syntax-entry ?) ")(4"  pascal-mode-syntax-table)    (modify-syntax-entry ?) ")(4"  pascal-mode-syntax-table)
143    (modify-syntax-entry ?* ". 23b" pascal-mode-syntax-table)    (modify-syntax-entry ?* ". 23b" pascal-mode-syntax-table)
144    (modify-syntax-entry ?{ "<"    pascal-mode-syntax-table)    (modify-syntax-entry ?{ "<"    pascal-mode-syntax-table)
# Line 252  are handled in another way, and should n Line 252  are handled in another way, and should n
252    "*Keywords to complete when standing at the first word of a statement.    "*Keywords to complete when standing at the first word of a statement.
253  These are keywords such as begin, repeat, until, readln.  These are keywords such as begin, repeat, until, readln.
254  The procedures and variables defined within the Pascal program  The procedures and variables defined within the Pascal program
255  are handled in another way,  and should not be added to this list."  are handled in another way, and should not be added to this list."
256    :type '(repeat (string :tag "Keyword"))    :type '(repeat (string :tag "Keyword"))
257    :group 'pascal)    :group 'pascal)
258    
# Line 283  are handled in another way, and should n Line 283  are handled in another way, and should n
283  (defun pascal-declaration-end ()  (defun pascal-declaration-end ()
284    (let ((nest 1))    (let ((nest 1))
285      (while (and (> nest 0)      (while (and (> nest 0)
286                  (re-search-forward                  (re-search-forward
287                   "[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)"                   "[:=]\\|\\(\\<record\\>\\)\\|\\(\\<end\\>\\)"
288                   (save-excursion (end-of-line 2) (point)) t))                   (save-excursion (end-of-line 2) (point)) t))
289        (cond ((match-beginning 1) (setq nest (1+ nest)))        (cond ((match-beginning 1) (setq nest (1+ nest)))
290              ((match-beginning 2) (setq nest (1- nest)))              ((match-beginning 2) (setq nest (1- nest)))
# Line 300  are handled in another way, and should n Line 300  are handled in another way, and should n
300              ((match-beginning 3) (setq nest (1+ nest)))))              ((match-beginning 3) (setq nest (1+ nest)))))
301      (= nest 0)))      (= nest 0)))
302    
303      
304  (defsubst pascal-within-string ()  (defsubst pascal-within-string ()
305    (save-excursion    (save-excursion
306      (nth 3 (parse-partial-sexp (pascal-get-beg-of-line) (point)))))      (nth 3 (parse-partial-sexp (pascal-get-beg-of-line) (point)))))
# Line 420  no args, if that value is non-nil." Line 420  no args, if that value is non-nil."
420                           (search-forward "*)" (pascal-get-end-of-line) t))))                           (search-forward "*)" (pascal-get-end-of-line) t))))
421               (setq setstar t))))               (setq setstar t))))
422      ;; If last line was a star comment line then this one shall be too.      ;; If last line was a star comment line then this one shall be too.
423      (if (null setstar)        (if (null setstar)
424          (pascal-indent-line)          (pascal-indent-line)
425        (insert "*  "))))        (insert "*  "))))
426    
# Line 602  area.  See also `pascal-comment-area'." Line 602  area.  See also `pascal-comment-area'."
602      (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))      (if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))
603          (forward-sexp 1))          (forward-sexp 1))
604      (let ((nest 0) (max -1) (func 0)      (let ((nest 0) (max -1) (func 0)
605            (reg (concat pascal-beg-block-re "\\|"            (reg (concat pascal-beg-block-re "\\|"
606                         pascal-end-block-re "\\|"                         pascal-end-block-re "\\|"
607                         pascal-defun-re)))                         pascal-defun-re)))
608        (while (re-search-backward reg nil 'move)        (while (re-search-backward reg nil 'move)
# Line 634  area.  See also `pascal-comment-area'." Line 634  area.  See also `pascal-comment-area'."
634        (pascal-beg-of-defun))        (pascal-beg-of-defun))
635    (forward-char 1)    (forward-char 1)
636    (let ((nest 0) (func 1)    (let ((nest 0) (func 1)
637          (reg (concat pascal-beg-block-re "\\|"          (reg (concat pascal-beg-block-re "\\|"
638                       pascal-end-block-re "\\|"                       pascal-end-block-re "\\|"
639                       pascal-defun-re)))                       pascal-defun-re)))
640      (while (and (/= func 0)      (while (and (/= func 0)
# Line 686  area.  See also `pascal-comment-area'." Line 686  area.  See also `pascal-comment-area'."
686          (catch 'found          (catch 'found
687            (while t            (while t
688              (re-search-forward regexp nil 'move)              (re-search-forward regexp nil 'move)
689              (setq nest (if (match-end 1)              (setq nest (if (match-end 1)
690                             (1+ nest)                             (1+ nest)
691                           (1- nest)))                           (1- nest)))
692              (cond ((eobp)              (cond ((eobp)
# Line 939  Return a list of two elements: (INDENT-T Line 939  Return a list of two elements: (INDENT-T
939                             )))))                             )))))
940    
941        ;; Return type of block and indent level.        ;; Return type of block and indent level.
942        (if (> par 0)                               ; Unclosed Parenthesis        (if (> par 0)                               ; Unclosed Parenthesis
943            (list 'contexp par)            (list 'contexp par)
944          (list type (pascal-indent-level))))))          (list type (pascal-indent-level))))))
945    
# Line 974  Do not count labels, case-statements or Line 974  Do not count labels, case-statements or
974          (ind 0))          (ind 0))
975      ;; Get right indent      ;; Get right indent
976      (while (< (point) end)      (while (< (point) end)
977        (if (re-search-forward        (if (re-search-forward
978             "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"             "^[ \t]*[^ \t,:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
979             (marker-position end) 'move)             (marker-position end) 'move)
980            (forward-char -1))            (forward-char -1))
# Line 1010  indent of the current line in parameterl Line 1010  indent of the current line in parameterl
1010      (let* ((oldpos (point))      (let* ((oldpos (point))
1011             (stpos (progn (goto-char (scan-lists (point) -1 1)) (point)))             (stpos (progn (goto-char (scan-lists (point) -1 1)) (point)))
1012             (stcol (1+ (current-column)))             (stcol (1+ (current-column)))
1013             (edpos (progn (pascal-declaration-end)             (edpos (progn (pascal-declaration-end)
1014                           (search-backward ")" (pascal-get-beg-of-line) t)                           (search-backward ")" (pascal-get-beg-of-line) t)
1015                           (point)))                           (point)))
1016             (usevar (re-search-backward "\\<var\\>" stpos t)))             (usevar (re-search-backward "\\<var\\>" stpos t)))
# Line 1032  indent of the current line in parameterl Line 1032  indent of the current line in parameterl
1032    (let ((pos (point-marker)))    (let ((pos (point-marker)))
1033      (if (and (not (or arg start)) (not (pascal-declaration-beg)))      (if (and (not (or arg start)) (not (pascal-declaration-beg)))
1034          ()          ()
1035        (let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start)        (let ((lineup (if (or (looking-at "\\<var\\>\\|\\<record\\>") arg start)
1036                          ":" "="))                          ":" "="))
1037              (stpos (if start start              (stpos (if start start
1038                         (forward-word 2) (backward-word 1) (point)))                         (forward-word 2) (backward-word 1) (point)))
# Line 1108  indent of the current line in parameterl Line 1108  indent of the current line in parameterl
1108          (end-of-line)          (end-of-line)
1109          (skip-chars-backward " \t")          (skip-chars-backward " \t")
1110          (1+ (current-column))))))          (1+ (current-column))))))
1111        
1112    
1113    
1114  ;;;  ;;;
# Line 1146  indent of the current line in parameterl Line 1146  indent of the current line in parameterl
1146                               (t "\\<\\(function\\|procedure\\)\\s +"))                               (t "\\<\\(function\\|procedure\\)\\s +"))
1147                              "\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>"))                              "\\<\\(" pascal-str "[a-zA-Z0-9_.]*\\)\\>"))
1148          match)          match)
1149        
1150      (if (not (looking-at "\\<\\(function\\|procedure\\)\\>"))      (if (not (looking-at "\\<\\(function\\|procedure\\)\\>"))
1151          (re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t))          (re-search-backward "\\<\\(function\\|procedure\\)\\>" nil t))
1152      (forward-char 1)      (forward-char 1)
# Line 1171  indent of the current line in parameterl Line 1171  indent of the current line in parameterl
1171      (while (< (point) end)      (while (< (point) end)
1172        (if (re-search-forward "[:=]" (pascal-get-end-of-line) t)        (if (re-search-forward "[:=]" (pascal-get-end-of-line) t)
1173            ;; Traverse current line            ;; Traverse current line
1174            (while (and (re-search-backward            (while (and (re-search-backward
1175                         (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|"                         (concat "\\((\\|\\<\\(var\\|type\\|const\\)\\>\\)\\|"
1176                                 pascal-symbol-re)                                 pascal-symbol-re)
1177                         (pascal-get-beg-of-line) t)                         (pascal-get-beg-of-line) t)
1178                        (not (match-end 1)))                        (not (match-end 1)))
# Line 1232  indent of the current line in parameterl Line 1232  indent of the current line in parameterl
1232    
1233  (defun pascal-keyword-completion (keyword-list)  (defun pascal-keyword-completion (keyword-list)
1234    "Give list of all possible completions of keywords in KEYWORD-LIST."    "Give list of all possible completions of keywords in KEYWORD-LIST."
1235    (mapcar '(lambda (s)    (mapcar '(lambda (s)
1236               (if (string-match (concat "\\<" pascal-str) s)               (if (string-match (concat "\\<" pascal-str) s)
1237                   (if (or (null pascal-pred)                   (if (or (null pascal-pred)
1238                           (funcall pascal-pred s))                           (funcall pascal-pred s))
# Line 1283  indent of the current line in parameterl Line 1283  indent of the current line in parameterl
1283                 (save-excursion (pascal-var-completion))                 (save-excursion (pascal-var-completion))
1284                 (pascal-func-completion 'function)                 (pascal-func-completion 'function)
1285                 (pascal-keyword-completion pascal-separator-keywords))))                 (pascal-keyword-completion pascal-separator-keywords))))
1286          
1287        ;; Now we have built a list of all matches. Give response to caller        ;; Now we have built a list of all matches. Give response to caller
1288        (pascal-completion-response))))        (pascal-completion-response))))
1289    
# Line 1352  indent of the current line in parameterl Line 1352  indent of the current line in parameterl
1352          (progn          (progn
1353            ;; Update entry number in list            ;; Update entry number in list
1354            (setq pascal-last-completions allcomp            (setq pascal-last-completions allcomp
1355                  pascal-last-word-numb                  pascal-last-word-numb
1356                  (if (>= pascal-last-word-numb (1- (length allcomp)))                  (if (>= pascal-last-word-numb (1- (length allcomp)))
1357                      0                      0
1358                    (1+ pascal-last-word-numb)))                    (1+ pascal-last-word-numb)))
# Line 1374  indent of the current line in parameterl Line 1374  indent of the current line in parameterl
1374               (if (not (null (cdr allcomp)))               (if (not (null (cdr allcomp)))
1375                   (message "(Complete but not unique)")                   (message "(Complete but not unique)")
1376                 (message "(Sole completion)")))                 (message "(Sole completion)")))
1377              ;; Display buffer if the current completion didn't help              ;; Display buffer if the current completion didn't help
1378              ;; on completing the label.              ;; on completing the label.
1379              ((and (not (null (cdr allcomp))) (= (length pascal-str)              ((and (not (null (cdr allcomp))) (= (length pascal-str)
1380                                                  (length match)))                                                  (length match)))
# Line 1447  With optional second arg non-nil, STR is Line 1447  With optional second arg non-nil, STR is
1447              (setq pascal-str (pascal-build-defun-re "[a-zA-Z_]"))              (setq pascal-str (pascal-build-defun-re "[a-zA-Z_]"))
1448            (setq pascal-str (pascal-build-defun-re pascal-str)))            (setq pascal-str (pascal-build-defun-re pascal-str)))
1449          (goto-char (point-min))          (goto-char (point-min))
1450          
1451          ;; Build a list of all possible completions          ;; Build a list of all possible completions
1452          (while (re-search-forward pascal-str nil t)          (while (re-search-forward pascal-str nil t)
1453            (setq match (buffer-substring (match-beginning 2) (match-end 2)))            (setq match (buffer-substring (match-beginning 2) (match-end 2)))
# Line 1547  Pascal Outline mode provides some additi Line 1547  Pascal Outline mode provides some additi
1547  (defun pascal-outline-change (b e pascal-flag)  (defun pascal-outline-change (b e pascal-flag)
1548    (let ((modp (buffer-modified-p)))    (let ((modp (buffer-modified-p)))
1549      (unwind-protect      (unwind-protect
1550          (subst-char-in-region b e (if (= pascal-flag ?\n)          (subst-char-in-region b e (if (= pascal-flag ?\n)
1551                                        ?\^M ?\n) pascal-flag)                                        ?\^M ?\n) pascal-flag)
1552        (set-buffer-modified-p modp))))        (set-buffer-modified-p modp))))
1553    

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.38.4.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26