Now on revision 111638. ------------------------------------------------------------ revno: 111638 fixes bug: http://debbugs.gnu.org/13522 committer: Glenn Morris branch nick: trunk timestamp: Wed 2013-01-30 22:35:45 -0800 message: Reduce delay between backing up a file and saving new version * lisp/files.el (basic-save-buffer-2): Choose coding system for writing the file before backing it up. * src/fileio.c (choose_write_coding_system): Make it callable from Lisp. (Fwrite_region): If coding-system-for-write is set, don't call choose_write_coding_system. Move the last piece of choose_write_coding_system here. (syms_of_fileio): Add choose-write-coding-system. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-31 02:57:35 +0000 +++ lisp/ChangeLog 2013-01-31 06:35:45 +0000 @@ -1,3 +1,9 @@ +2013-01-31 Glenn Morris + + * files.el (basic-save-buffer-2): Choose coding system for + writing the file before backing it up, to reduce delay between + backing up and writing the new version. (Bug#13522) + 2013-01-31 Michal Nazarewicz * simple.el (cycle-spacing): New command. === modified file 'lisp/files.el' --- lisp/files.el 2013-01-10 15:50:04 +0000 +++ lisp/files.el 2013-01-31 06:35:45 +0000 @@ -4656,7 +4656,7 @@ ;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like ;; backup-buffer. (defun basic-save-buffer-2 () - (let (tempsetmodes setmodes) + (let (tempsetmodes setmodes writecoding) (if (not (file-writable-p buffer-file-name)) (let ((dir (file-name-directory buffer-file-name))) (if (not (file-directory-p dir)) @@ -4672,6 +4672,14 @@ buffer-file-name))) (setq tempsetmodes t) (error "Attempt to save to a file which you aren't allowed to write")))))) + ;; This may involve prompting, so do it now before backing up the file. + ;; Otherwise there can be a delay while the user answers the + ;; prompt during which the original file has been renamed. (Bug#13522) + (setq writecoding + ;; Args here should match write-region call below around + ;; which we use writecoding. + (choose-write-coding-system nil nil buffer-file-name nil t + buffer-file-truename)) (or buffer-backed-up (setq setmodes (backup-buffer))) (let* ((dir (file-name-directory buffer-file-name)) @@ -4753,10 +4761,11 @@ (logior (car setmodes) 128)))))) (let (success) (unwind-protect - (progn ;; Pass in nil&nil rather than point-min&max to indicate ;; we're saving the buffer rather than just a region. ;; write-region-annotate-functions may make us of it. + (let ((coding-system-for-write writecoding) + (coding-system-require-warning nil)) (write-region nil nil buffer-file-name nil t buffer-file-truename) (setq success t)) === modified file 'src/ChangeLog' --- src/ChangeLog 2013-01-30 08:07:37 +0000 +++ src/ChangeLog 2013-01-31 06:35:45 +0000 @@ -1,3 +1,11 @@ +2013-01-31 Glenn Morris + + * fileio.c (choose_write_coding_system): Make it callable from Lisp. + (Fwrite_region): If coding-system-for-write is set, don't + call choose_write_coding_system. Move the last piece of + choose_write_coding_system here. (Bug#13522) + (syms_of_fileio): Add choose-write-coding-system. + 2013-01-30 Eli Zaretskii * w32.c (sys_open): Zero out the flags for the new file descriptor. === modified file 'src/fileio.c' --- src/fileio.c 2013-01-23 20:07:28 +0000 +++ src/fileio.c 2013-01-31 06:35:45 +0000 @@ -249,6 +249,7 @@ static Lisp_Object Qset_file_acl; static Lisp_Object Qfile_newer_than_file_p; Lisp_Object Qinsert_file_contents; +Lisp_Object Qchoose_write_coding_system; Lisp_Object Qwrite_region; static Lisp_Object Qverify_visited_file_modtime; static Lisp_Object Qset_visited_file_modtime; @@ -4615,14 +4616,24 @@ /* Decide the coding-system to encode the data with. */ -static Lisp_Object -choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object filename, - Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, - struct coding_system *coding) +DEFUN ("choose-write-coding-system", Fchoose_write_coding_system, + Schoose_write_coding_system, 3, 6, 0, + doc: /* Choose the coding system for writing a file. +Arguments are as for `write-region'. +This function is for internal use only. It may prompt the user. */ ) + (Lisp_Object start, Lisp_Object end, Lisp_Object filename, + Lisp_Object append, Lisp_Object visit, Lisp_Object lockname) { Lisp_Object val; Lisp_Object eol_parent = Qnil; + /* Mimic write-region behavior. */ + if (NILP (start)) + { + XSETFASTINT (start, BEGV); + XSETFASTINT (end, ZV); + } + if (auto_saving && NILP (Fstring_equal (BVAR (current_buffer, filename), BVAR (current_buffer, auto_save_file_name)))) @@ -4715,10 +4726,6 @@ } val = coding_inherit_eol_type (val, eol_parent); - setup_coding_system (val, coding); - - if (!STRINGP (start) && !NILP (BVAR (current_buffer, selective_display))) - coding->mode |= CODING_MODE_SELECTIVE_DISPLAY; return val; } @@ -4874,9 +4881,15 @@ We used to make this choice before calling build_annotations, but that leads to problems when a write-annotate-function takes care of unsavable chars (as was the case with X-Symbol). */ - Vlast_coding_system_used - = choose_write_coding_system (start, end, filename, - append, visit, lockname, &coding); + Vlast_coding_system_used = NILP (Vcoding_system_for_write) ? + Fchoose_write_coding_system (start, end, filename, + append, visit, lockname) : + Vcoding_system_for_write; + + setup_coding_system (Vlast_coding_system_used, &coding); + + if (!STRINGP (start) && !NILP (BVAR (current_buffer, selective_display))) + coding.mode |= CODING_MODE_SELECTIVE_DISPLAY; #ifdef CLASH_DETECTION if (!auto_saving) @@ -5861,6 +5874,7 @@ DEFSYM (Qset_file_acl, "set-file-acl"); DEFSYM (Qfile_newer_than_file_p, "file-newer-than-file-p"); DEFSYM (Qinsert_file_contents, "insert-file-contents"); + DEFSYM (Qchoose_write_coding_system, "choose-write-coding-system"); DEFSYM (Qwrite_region, "write-region"); DEFSYM (Qverify_visited_file_modtime, "verify-visited-file-modtime"); DEFSYM (Qset_visited_file_modtime, "set-visited-file-modtime"); @@ -6085,6 +6099,7 @@ defsubr (&Sdefault_file_modes); defsubr (&Sfile_newer_than_file_p); defsubr (&Sinsert_file_contents); + defsubr (&Schoose_write_coding_system); defsubr (&Swrite_region); defsubr (&Scar_less_than_car); defsubr (&Sverify_visited_file_modtime); ------------------------------------------------------------ revno: 111637 author: Michal Nazarewicz committer: Stefan Monnier branch nick: trunk timestamp: Wed 2013-01-30 21:57:35 -0500 message: * lisp/simple.el (cycle-spacing): New command. (just-one-space): Use it. diff: === modified file 'etc/NEWS' --- etc/NEWS 2013-01-31 01:58:24 +0000 +++ etc/NEWS 2013-01-31 02:57:35 +0000 @@ -163,6 +163,11 @@ it works like the utility `uniq'. Otherwise by default it deletes duplicate lines everywhere in the region without regard to adjacency. +** New `cycle-spacing' command allows cycling between having just one +space, no spaces, or reverting to the original spacing. Like +`just-one-space' command it can handle or ignore newlines and +leave different number of spaces. + ** Tramp +++ *** New connection method "adb", which allows to access Android === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-31 01:58:24 +0000 +++ lisp/ChangeLog 2013-01-31 02:57:35 +0000 @@ -1,3 +1,8 @@ +2013-01-31 Michal Nazarewicz + + * simple.el (cycle-spacing): New command. + (just-one-space): Use it. + 2013-01-31 Stefan Monnier * progmodes/opascal.el: Rename from delphi.el. Use lexical-binding. === modified file 'lisp/simple.el' --- lisp/simple.el 2013-01-11 23:08:55 +0000 +++ lisp/simple.el 2013-01-31 02:57:35 +0000 @@ -746,21 +746,76 @@ "Delete all spaces and tabs around point, leaving one space (or N spaces). If N is negative, delete newlines as well, leaving -N spaces." (interactive "*p") - (unless n (setq n 1)) - (let ((orig-pos (point)) - (skip-characters (if (< n 0) " \t\n\r" " \t")) - (n (abs n))) - (skip-chars-backward skip-characters) + (cycle-spacing n nil t)) + +(defvar cycle-spacing--context nil + "Store context used in consecutive calls to `cycle-spacing' command. +The first time this function is run, it saves the original point +position and original spacing around the point in this +variable.") + +(defun cycle-spacing (&optional n preserve-nl-back single-shot) + "Manipulate spaces around the point in a smart way. + +When run as an interactive command, the first time it's called +in a sequence, deletes all spaces and tabs around point leaving +one (or N spaces). If this does not change content of the +buffer, skips to the second step: + +When run for the second time in a sequence, deletes all the +spaces it has previously inserted. + +When run for the third time, returns the whitespace and point in +a state encountered when it had been run for the first time. + +For example, if buffer contains \"foo ^ bar\" with \"^\" denoting the +point, calling `cycle-spacing' command will replace two spaces with +a single space, calling it again immediately after, will remove all +spaces, and calling it for the third time will bring two spaces back +together. + +If N is negative, delete newlines as well. However, if +PRESERVE-NL-BACK is t new line characters prior to the point +won't be removed. + +If SINGLE-SHOT is non-nil, will only perform the first step. In +other words, it will work just like `just-one-space' command." + (interactive "*p") + (let ((orig-pos (point)) + (skip-characters (if (and n (< n 0)) " \t\n\r" " \t")) + (n (abs (or n 1)))) + (skip-chars-backward (if preserve-nl-back " \t" skip-characters)) (constrain-to-field nil orig-pos) - (dotimes (_ n) - (if (= (following-char) ?\s) - (forward-char 1) - (insert ?\s))) - (delete-region - (point) - (progn - (skip-chars-forward skip-characters) - (constrain-to-field nil orig-pos t))))) + (cond + ;; Command run for the first time or single-shot is non-nil. + ((or single-shot + (not (equal last-command this-command)) + (not cycle-spacing--context)) + (let* ((start (point)) + (n (- n (skip-chars-forward " " (+ n (point))))) + (mid (point)) + (end (progn + (skip-chars-forward skip-characters) + (constrain-to-field nil orig-pos t)))) + (setq cycle-spacing--context ;; Save for later. + ;; Special handling for case where there was no space at all. + (unless (= start end) + (cons orig-pos (buffer-substring start (point))))) + ;; If this run causes no change in buffer content, delete all spaces, + ;; otherwise delete all excees spaces. + (delete-region (if (and (not single-shot) (zerop n) (= mid end)) + start mid) end) + (insert (make-string ?\s n)))) + + ;; Command run for the second time. + ((not (equal orig-pos (point))) + (delete-region (point) orig-pos)) + + ;; Command run for the third time. + (t + (insert (cdr cycle-spacing--context)) + (goto-char (car cycle-spacing--context)) + (setq cycle-spacing--context nil))))) (defun beginning-of-buffer (&optional arg) "Move point to the beginning of the buffer. ------------------------------------------------------------ revno: 111636 committer: Stefan Monnier branch nick: trunk timestamp: Wed 2013-01-30 20:58:24 -0500 message: * lisp/progmodes/opascal.el: Rename from delphi.el. Use lexical-binding. (opascal-newline-always-indents): Remove custom. (opascal-tab, opascal-newline): Remove commands. (opascal-new-comment-line): Insert "\n" instead of calling newline. (opascal-mode-map): Keep default bindings for RET and TAB and DEL. (opascal-save-match-data): Remove, use save-match-data instead. (opascal-save-state): Use with-silent-modifications. diff: === modified file 'etc/NEWS' --- etc/NEWS 2013-01-20 18:06:54 +0000 +++ etc/NEWS 2013-01-31 01:58:24 +0000 @@ -71,6 +71,12 @@ * Changes in Specialized Modes and Packages in Emacs 24.4 +** Delphi mode is now called OPascal mode. +*** All delphi-* variables and functions have been renamed to opascal-*. +*** `delphi-newline-always-indents' is not supported any more +use `electric-indent-mode' instead. +*** `delphi-tab' is gone, replaced by `indent-for-tab-command'. + ** jit-lock-debug-mode lets you use the debuggers on code run via jit-lock. ** completing-read-multiple's separator can now be a regexp. === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-31 00:58:24 +0000 +++ lisp/ChangeLog 2013-01-31 01:58:24 +0000 @@ -1,5 +1,13 @@ 2013-01-31 Stefan Monnier + * progmodes/opascal.el: Rename from delphi.el. Use lexical-binding. + (opascal-newline-always-indents): Remove custom. + (opascal-tab, opascal-newline): Remove commands. + (opascal-new-comment-line): Insert "\n" instead of calling newline. + (opascal-mode-map): Keep default bindings for RET and TAB and DEL. + (opascal-save-match-data): Remove, use save-match-data instead. + (opascal-save-state): Use with-silent-modifications. + * progmodes/pascal.el (pascal-mode-syntax-table): Accept //..\n comments (bug#13585). === renamed file 'lisp/progmodes/delphi.el' => 'lisp/progmodes/opascal.el' --- lisp/progmodes/delphi.el 2013-01-01 09:11:05 +0000 +++ lisp/progmodes/opascal.el 2013-01-31 01:58:24 +0000 @@ -1,4 +1,4 @@ -;;; delphi.el --- major mode for editing Delphi source (Object Pascal) in Emacs +;;; opascal.el --- major mode for editing Object Pascal source in Emacs -*- lexical-binding: t -*- ;; Copyright (C) 1998-1999, 2001-2013 Free Software Foundation, Inc. @@ -24,74 +24,55 @@ ;;; Commentary: -;; To enter Delphi mode when you find a Delphi source file, one must override -;; the auto-mode-alist to associate Delphi with .pas (and .dpr and .dpk) -;; files. Emacs, by default, will otherwise enter Pascal mode. E.g. -;; -;; (autoload 'delphi-mode "delphi") -;; (setq auto-mode-alist -;; (cons '("\\.\\(pas\\|dpr\\|dpk\\)$" . delphi-mode) auto-mode-alist)) - -;; To get keyword, comment, and string literal coloring, be sure that font-lock -;; is running. One can manually do M-x font-lock-mode in a Delphi buffer, or -;; one can put in .emacs: -;; -;; (add-hook 'delphi-mode-hook 'turn-on-font-lock) - -;; If font-lock is not loaded by default, you might have to do: -;; -;; (autoload 'font-lock-mode "font-lock") -;; (autoload 'turn-on-font-lock "font-lock") -;; (setq font-lock-support-mode 'lazy-lock-mode) -;; -;; Lazy lock is very necessary for faster screen updates. - -;; For good performance, be sure to byte-compile delphi.el, e.g. -;; -;; M-x byte-compile-file - -;; This will generate delphi.elc, which will be loaded instead of delphi.el -;; when delphi-mode is autoloaded. - -;; When you have entered Delphi mode, you may get more info by pressing +;; To enter OPascal mode when you find an Object Pascal source file, one must +;; override the auto-mode-alist to associate OPascal with .pas (and .dpr and +;; .dpk) files. Emacs, by default, will otherwise enter Pascal mode. E.g. +;; +;; (autoload 'opascal-mode "opascal") +;; (add-to-list 'auto-mode-alist +;; '("\\.\\(pas\\|dpr\\|dpk\\)\\'" . opascal-mode)) + +;; When you have entered OPascal mode, you may get more info by pressing ;; C-h m. -;; This Delphi mode implementation is fairly tolerant of syntax errors, relying -;; as much as possible on the indentation of the previous statement. This also -;; makes it faster and simpler, since there is less searching for properly -;; constructed beginnings. +;; This OPascal mode implementation is fairly tolerant of syntax errors, +;; relying as much as possible on the indentation of the previous statement. +;; This also makes it faster and simpler, since there is less searching for +;; properly constructed beginnings. ;;; Code: -(provide 'delphi) - -(defgroup delphi nil - "Major mode for editing Delphi source in Emacs." - :version "21.1" +(defgroup opascal nil + "Major mode for editing OPascal source in Emacs." + :version "24.4" :group 'languages) -(defconst delphi-debug nil +(defconst opascal-debug nil "True if in debug mode.") -(defcustom delphi-search-path "." +(define-obsolete-variable-alias + 'delphi-search-path 'opascal-search-path "24.4") +(defcustom opascal-search-path "." "Directories to search when finding external units. It is a list of directory strings. If only a single directory, it can be a single string instead of a list. If a directory ends in \"...\" then that directory is recursively searched." - :type 'string - :group 'delphi) + :type 'string) -(defcustom delphi-indent-level 3 - "Indentation of Delphi statements with respect to containing block. +(define-obsolete-variable-alias + 'delphi-indent-level 'opascal-indent-level "24.4") +(defcustom opascal-indent-level 3 + "Indentation of OPascal statements with respect to containing block. E.g. begin // This is an indent of 3. end;" - :type 'integer - :group 'delphi) + :type 'integer) -(defcustom delphi-compound-block-indent 0 +(define-obsolete-variable-alias + 'delphi-compound-block-indent 'opascal-compound-block-indent "24.4") +(defcustom opascal-compound-block-indent 0 "Extra indentation for blocks in compound statements. E.g. // block indent = 0 vs // block indent = 2 @@ -101,10 +82,11 @@ end; else begin end;" - :type 'integer - :group 'delphi) + :type 'integer) -(defcustom delphi-case-label-indent delphi-indent-level +(define-obsolete-variable-alias + 'delphi-case-label-indent 'opascal-case-label-indent "24.4") +(defcustom opascal-case-label-indent opascal-indent-level "Extra indentation for case statement labels. E.g. // case indent = 0 vs // case indent = 3 @@ -114,58 +96,52 @@ else else process_else; process_else; end; end;" - :type 'integer - :group 'delphi) - -(defcustom delphi-verbose t ; nil - "If true then Delphi token processing progress is reported to the user." - :type 'boolean - :group 'delphi) - -(defcustom delphi-tab-always-indents t - "Non-nil means TAB in Delphi mode should always reindent the current line, + :type 'integer) + +(define-obsolete-variable-alias 'delphi-verbose 'opascal-verbose "24.4") +(defcustom opascal-verbose t ; nil + "If true then OPascal token processing progress is reported to the user." + :type 'boolean) + +(define-obsolete-variable-alias + 'delphi-tab-always-indents 'opascal-tab-always-indents "24.4") +(defcustom opascal-tab-always-indents tab-always-indent + "Non-nil means TAB in OPascal mode should always reindent the current line, regardless of where in the line point is when the TAB command is used." - :type 'boolean - :group 'delphi) - -(defcustom delphi-newline-always-indents t - "Non-nil means NEWLINE in Delphi mode should always reindent the current -line, insert a blank line and move to the default indent column of the blank -line. If nil, then no indentation occurs, and NEWLINE does the usual -behavior. This is useful when one needs to do customized indentation that -differs from the default." - :type 'boolean - :group 'delphi) - -(defcustom delphi-comment-face 'font-lock-comment-face - "Face used to color Delphi comments." - :type 'face - :group 'delphi) - -(defcustom delphi-string-face 'font-lock-string-face - "Face used to color Delphi strings." - :type 'face - :group 'delphi) - -(defcustom delphi-keyword-face 'font-lock-keyword-face - "Face used to color Delphi keywords." - :type 'face - :group 'delphi) - -(defcustom delphi-other-face nil + :type 'boolean) + +(define-obsolete-variable-alias + 'delphi-comment-face 'opascal-comment-face "24.4") +(defcustom opascal-comment-face 'font-lock-comment-face + "Face used to color OPascal comments." + :type 'face) + +(define-obsolete-variable-alias + 'delphi-string-face 'opascal-string-face "24.4") +(defcustom opascal-string-face 'font-lock-string-face + "Face used to color OPascal strings." + :type 'face) + +(define-obsolete-variable-alias + 'delphi-keyword-face 'opascal-keyword-face "24.4") +(defcustom opascal-keyword-face 'font-lock-keyword-face + "Face used to color OPascal keywords." + :type 'face) + +(define-obsolete-variable-alias 'delphi-other-face 'opascal-other-face "24.4") +(defcustom opascal-other-face nil "Face used to color everything else." - :type '(choice (const :tag "None" nil) face) - :group 'delphi) + :type '(choice (const :tag "None" nil) face)) -(defconst delphi-directives +(defconst opascal-directives '(absolute abstract assembler automated cdecl default dispid dynamic export external far forward index inline message name near nodefault overload override pascal private protected public published read readonly register reintroduce resident resourcestring safecall stdcall stored virtual write writeonly) - "Delphi4 directives.") + "OPascal4 directives.") -(defconst delphi-keywords +(defconst opascal-keywords (append '(;; Keywords. and array as asm at begin case class const constructor contains @@ -180,261 +156,241 @@ break exit) ;; We want directives to look like keywords. - delphi-directives) - "Delphi4 keywords.") + opascal-directives) + "OPascal4 keywords.") -(defconst delphi-previous-terminators `(semicolon comma) +(defconst opascal-previous-terminators `(semicolon comma) "Expression/statement terminators that denote a previous expression.") -(defconst delphi-comments +(defconst opascal-comments '(comment-single-line comment-multi-line-1 comment-multi-line-2) "Tokens that represent comments.") -(defconst delphi-strings +(defconst opascal-strings '(string double-quoted-string) "Tokens that represent string literals.") -(defconst delphi-whitespace `(space newline ,@delphi-comments) +(defconst opascal-whitespace `(space newline ,@opascal-comments) "Tokens that are considered whitespace.") -(defconst delphi-routine-statements +(defconst opascal-routine-statements '(procedure function constructor destructor property) "Marks the start of a routine, or routine-ish looking expression.") -(defconst delphi-body-expr-statements '(if while for on) +(defconst opascal-body-expr-statements '(if while for on) "Statements that have either a single statement or a block as a body and also are followed by an expression.") -(defconst delphi-expr-statements `(case ,@delphi-body-expr-statements) +(defconst opascal-expr-statements `(case ,@opascal-body-expr-statements) "Expression statements contain expressions after their keyword.") -(defconst delphi-body-statements `(else ,@delphi-body-expr-statements) +(defconst opascal-body-statements `(else ,@opascal-body-expr-statements) "Statements that have either a single statement or a block as a body.") -(defconst delphi-expr-delimiters '(then do of) +(defconst opascal-expr-delimiters '(then do of) "Expression delimiter tokens.") -(defconst delphi-binary-ops +(defconst opascal-binary-ops '(plus minus equals not-equals times divides div mod and or xor) - "Delphi binary operations.") + "OPascal binary operations.") -(defconst delphi-visibilities '(public private protected published automated) +(defconst opascal-visibilities '(public private protected published automated) "Class visibilities.") -(defconst delphi-block-statements +(defconst opascal-block-statements '(begin try case repeat initialization finalization asm) "Statements that contain multiple substatements.") -(defconst delphi-mid-block-statements - `(except finally ,@delphi-visibilities) +(defconst opascal-mid-block-statements + `(except finally ,@opascal-visibilities) "Statements that mark mid sections of the enclosing block.") -(defconst delphi-end-block-statements `(end until) +(defconst opascal-end-block-statements `(end until) "Statements that end block sections.") -(defconst delphi-match-block-statements - `(,@delphi-end-block-statements ,@delphi-mid-block-statements) +(defconst opascal-match-block-statements + `(,@opascal-end-block-statements ,@opascal-mid-block-statements) "Statements that match the indentation of the parent block.") -(defconst delphi-decl-sections '(type const var label resourcestring) +(defconst opascal-decl-sections '(type const var label resourcestring) "Denotes the start of a declaration section.") -(defconst delphi-interface-types '(dispinterface interface) +(defconst opascal-interface-types '(dispinterface interface) "Interface types.") -(defconst delphi-class-types '(class object) +(defconst opascal-class-types '(class object) "Class types.") -(defconst delphi-composite-types - `(,@delphi-class-types ,@delphi-interface-types record) +(defconst opascal-composite-types + `(,@opascal-class-types ,@opascal-interface-types record) "Types that contain declarations within them.") -(defconst delphi-unit-sections +(defconst opascal-unit-sections '(interface implementation program library package) "Unit sections within which the indent is 0.") -(defconst delphi-use-clauses `(uses requires exports contains) +(defconst opascal-use-clauses `(uses requires exports contains) "Statements that refer to foreign symbols.") -(defconst delphi-unit-statements - `(,@delphi-use-clauses ,@delphi-unit-sections initialization finalization) +(defconst opascal-unit-statements + `(,@opascal-use-clauses ,@opascal-unit-sections initialization finalization) "Statements indented at level 0.") -(defconst delphi-decl-delimiters - `(,@delphi-decl-sections ,@delphi-unit-statements - ,@delphi-routine-statements) +(defconst opascal-decl-delimiters + `(,@opascal-decl-sections ,@opascal-unit-statements + ,@opascal-routine-statements) "Statements that a declaration statement should align with.") -(defconst delphi-decl-matchers - `(begin ,@delphi-decl-sections) +(defconst opascal-decl-matchers + `(begin ,@opascal-decl-sections) "Statements that should match to declaration statement indentation.") -(defconst delphi-enclosing-statements - `(,@delphi-block-statements ,@delphi-mid-block-statements - ,@delphi-decl-sections ,@delphi-use-clauses ,@delphi-routine-statements) +(defconst opascal-enclosing-statements + `(,@opascal-block-statements ,@opascal-mid-block-statements + ,@opascal-decl-sections ,@opascal-use-clauses ,@opascal-routine-statements) "Delimits an enclosing statement.") -(defconst delphi-previous-statements - `(,@delphi-unit-statements ,@delphi-routine-statements) +(defconst opascal-previous-statements + `(,@opascal-unit-statements ,@opascal-routine-statements) "Delimits a previous statement.") -(defconst delphi-previous-enclosing-statements - `(,@delphi-block-statements ,@delphi-mid-block-statements - ,@delphi-decl-sections) +(defconst opascal-previous-enclosing-statements + `(,@opascal-block-statements ,@opascal-mid-block-statements + ,@opascal-decl-sections) "Delimits a previous enclosing statement.") -(defconst delphi-begin-enclosing-tokens - `(,@delphi-block-statements ,@delphi-mid-block-statements) +(defconst opascal-begin-enclosing-tokens + `(,@opascal-block-statements ,@opascal-mid-block-statements) "Tokens that a begin token indents from.") -(defconst delphi-begin-previous-tokens - `(,@delphi-decl-sections ,@delphi-routine-statements) +(defconst opascal-begin-previous-tokens + `(,@opascal-decl-sections ,@opascal-routine-statements) "Tokens that a begin token aligns with, but only if not part of a nested routine.") -(defconst delphi-space-chars "\000-\011\013- ") ; all except \n -(defconst delphi-non-space-chars (concat "^" delphi-space-chars)) -(defconst delphi-spaces-re (concat "[" delphi-space-chars "]*")) -(defconst delphi-leading-spaces-re (concat "^" delphi-spaces-re)) -(defconst delphi-word-chars "a-zA-Z0-9_") - -(defmacro delphi-save-match-data (&rest forms) - ;; Executes the forms such that the current match data is preserved, so as - ;; not to disturb any existing search results. - `(let ((data (match-data))) - (unwind-protect - (progn ,@forms) - (set-match-data data)))) - -(defmacro delphi-save-excursion (&rest forms) +(defconst opascal-space-chars "\000-\011\013- ") ; all except \n +(defconst opascal-non-space-chars (concat "^" opascal-space-chars)) +(defconst opascal-spaces-re (concat "[" opascal-space-chars "]*")) +(defconst opascal-leading-spaces-re (concat "^" opascal-spaces-re)) +(defconst opascal-word-chars "a-zA-Z0-9_") + +(defmacro opascal-save-excursion (&rest forms) ;; Executes the forms such that any movements have no effect, including ;; searches. `(save-excursion - (delphi-save-match-data + (save-match-data (let ((inhibit-point-motion-hooks t) (deactivate-mark nil)) (progn ,@forms))))) -(defmacro delphi-save-state (&rest forms) +(defmacro opascal-save-state (&rest forms) ;; Executes the forms such that any buffer modifications do not have any side ;; effects beyond the buffer's actual content changes. - `(let ((delphi-ignore-changes t) - (old-supersession-threat - (symbol-function 'ask-user-about-supersession-threat)) - (buffer-read-only nil) - (inhibit-read-only t) - (buffer-undo-list t) - (before-change-functions nil) - (after-change-functions nil) - (modified (buffer-modified-p))) - ;; Disable any queries about editing obsolete files. - (fset 'ask-user-about-supersession-threat (lambda (_fn))) - (unwind-protect - (progn ,@forms) - (set-buffer-modified-p modified) - (fset 'ask-user-about-supersession-threat old-supersession-threat)))) + `(let ((opascal--ignore-changes t)) + (with-silent-modifications + ,@forms))) -(defsubst delphi-is (element in-set) +(defsubst opascal-is (element in-set) ;; If the element is in the set, the element cdr is returned, otherwise nil. (memq element in-set)) -(defun delphi-string-of (start end) +(defun opascal-string-of (start end) ;; Returns the buffer string from start to end. (buffer-substring-no-properties start end)) -(defun delphi-looking-at-string (p s) +(defun opascal-looking-at-string (p s) ;; True if point p marks the start of string s. s is not a regular ;; expression. (let ((limit (+ p (length s)))) (and (<= limit (point-max)) - (string= s (delphi-string-of p limit))))) + (string= s (opascal-string-of p limit))))) -(defun delphi-token-of (kind start end) +(defun opascal-token-of (kind start end) ;; Constructs a token from a kind symbol and its start/end points. `[,kind ,start ,end]) -(defsubst delphi-token-kind (token) +(defsubst opascal-token-kind (token) ;; Returns the kind symbol of the token. (if token (aref token 0) nil)) -(defun delphi-set-token-kind (token to-kind) +(defun opascal-set-token-kind (token to-kind) ;; Sets the kind symbol of the token. (if token (aset token 0 to-kind))) -(defsubst delphi-token-start (token) +(defsubst opascal-token-start (token) ;; Returns the start point of the token. (if token (aref token 1) (point-min))) -(defsubst delphi-token-end (token) +(defsubst opascal-token-end (token) ;; Returns the end point of the token. (if token (aref token 2) (point-min))) -(defun delphi-set-token-start (token start) +(defun opascal-set-token-start (token start) ;; Sets the start point of the token. (if token (aset token 1 start))) -(defun delphi-set-token-end (token end) +(defun opascal-set-token-end (token end) ;; Sets the end point of the token. (if token (aset token 2 end))) -(defun delphi-token-string (token) +(defun opascal-token-string (token) ;; Returns the string image of the token. (if token - (delphi-string-of (delphi-token-start token) (delphi-token-end token)) + (opascal-string-of (opascal-token-start token) (opascal-token-end token)) "")) -(defun delphi-in-token (p token) +(defun opascal-in-token (p token) ;; Returns true if the point p is within the token's start/end points. - (and (<= (delphi-token-start token) p) (< p (delphi-token-end token)))) + (and (<= (opascal-token-start token) p) (< p (opascal-token-end token)))) -(defun delphi-column-of (p) +(defun opascal-column-of (p) ;; Returns the column of the point p. (save-excursion (goto-char p) (current-column))) -(defun delphi-face-of (token-kind) +(defun opascal-face-of (token-kind) ;; Returns the face property appropriate for the token kind. - (cond ((delphi-is token-kind delphi-comments) delphi-comment-face) - ((delphi-is token-kind delphi-strings) delphi-string-face) - ((delphi-is token-kind delphi-keywords) delphi-keyword-face) - (delphi-other-face))) + (cond ((opascal-is token-kind opascal-comments) opascal-comment-face) + ((opascal-is token-kind opascal-strings) opascal-string-face) + ((opascal-is token-kind opascal-keywords) opascal-keyword-face) + (opascal-other-face))) -(defvar delphi-progress-last-reported-point nil +(defvar opascal-progress-last-reported-point nil "The last point at which progress was reported.") -(defconst delphi-parsing-progress-step 16384 +(defconst opascal-parsing-progress-step 16384 "Number of chars to process before the next parsing progress report.") -(defconst delphi-scanning-progress-step 2048 +(defconst opascal-scanning-progress-step 2048 "Number of chars to process before the next scanning progress report.") -(defconst delphi-fontifying-progress-step delphi-scanning-progress-step +(defconst opascal-fontifying-progress-step opascal-scanning-progress-step "Number of chars to process before the next fontification progress report.") -(defun delphi-progress-start () +(defun opascal-progress-start () ;; Initializes progress reporting. - (setq delphi-progress-last-reported-point nil)) + (setq opascal-progress-last-reported-point nil)) -(defun delphi-progress-done (&rest msgs) +(defun opascal-progress-done (&rest msgs) ;; Finalizes progress reporting. - (setq delphi-progress-last-reported-point nil) - (when delphi-verbose + (setq opascal-progress-last-reported-point nil) + (when opascal-verbose (if (null msgs) (message "") (apply #'message msgs)))) -(defun delphi-step-progress (p desc step-size) +(defun opascal-step-progress (p desc step-size) ;; If enough distance has elapsed since the last reported point, then report ;; the current progress to the user. - (cond ((null delphi-progress-last-reported-point) + (cond ((null opascal-progress-last-reported-point) ;; This is the first progress step. - (setq delphi-progress-last-reported-point p)) + (setq opascal-progress-last-reported-point p)) - ((and delphi-verbose - (>= (abs (- p delphi-progress-last-reported-point)) step-size)) + ((and opascal-verbose + (>= (abs (- p opascal-progress-last-reported-point)) step-size)) ;; Report the percentage complete. - (setq delphi-progress-last-reported-point p) + (setq opascal-progress-last-reported-point p) (message "%s %s ... %d%%" desc (buffer-name) (/ (* 100 p) (point-max)))))) -(defun delphi-next-line-start (&optional from-point) +(defun opascal-next-line-start (&optional from-point) ;; Returns the first point of the next line. (let ((curr-point (point)) (next nil)) @@ -444,24 +400,24 @@ (goto-char curr-point) next)) -(defvar delphi-ignore-changes t - "Internal flag to control if the Delphi mode responds to buffer changes. -Defaults to t in case the `delphi-after-change' function is called on a -non-Delphi buffer. Set to nil in a Delphi buffer. To override, just do: - (let ((delphi-ignore-changes t)) ...)") +(defvar opascal--ignore-changes t + "Internal flag to control if the OPascal mode responds to buffer changes. +Defaults to t in case the `opascal-after-change' function is called on a +non-OPascal buffer. Set to nil in OPascal buffers. To override, just do: + (let ((opascal--ignore-changes t)) ...)") -(defun delphi-set-text-properties (from to properties) +(defun opascal-set-text-properties (from to properties) ;; Like `set-text-properties', except we do not consider this to be a buffer ;; modification. - (delphi-save-state + (opascal-save-state (set-text-properties from to properties))) -(defun delphi-literal-kind (p) +(defun opascal-literal-kind (p) ;; Returns the literal kind the point p is in (or nil if not in a literal). (if (and (<= (point-min) p) (<= p (point-max))) (get-text-property p 'token))) -(defun delphi-literal-start-pattern (literal-kind) +(defun opascal-literal-start-pattern (literal-kind) ;; Returns the start pattern of the literal kind. (cdr (assoc literal-kind '((comment-single-line . "//") @@ -470,7 +426,7 @@ (string . "'") (double-quoted-string . "\""))))) -(defun delphi-literal-end-pattern (literal-kind) +(defun opascal-literal-end-pattern (literal-kind) ;; Returns the end pattern of the literal kind. (cdr (assoc literal-kind '((comment-single-line . "\n") @@ -479,7 +435,7 @@ (string . "'") (double-quoted-string . "\""))))) -(defun delphi-literal-stop-pattern (literal-kind) +(defun opascal-literal-stop-pattern (literal-kind) ;; Returns the pattern that delimits end of the search for the literal kind. ;; These are regular expressions. (cdr (assoc literal-kind @@ -490,69 +446,69 @@ (string . "['\n]") (double-quoted-string . "[\"\n]"))))) -(defun delphi-is-literal-start (p) +(defun opascal-is-literal-start (p) ;; True if the point p is at the start point of a (completed) literal. - (let* ((kind (delphi-literal-kind p)) - (pattern (delphi-literal-start-pattern kind))) + (let* ((kind (opascal-literal-kind p)) + (pattern (opascal-literal-start-pattern kind))) (or (null kind) ; Non-literals are considered as start points. - (delphi-looking-at-string p pattern)))) + (opascal-looking-at-string p pattern)))) -(defun delphi-is-literal-end (p) +(defun opascal-is-literal-end (p) ;; True if the point p is at the end point of a (completed) literal. - (let* ((kind (delphi-literal-kind (1- p))) - (pattern (delphi-literal-end-pattern kind))) + (let* ((kind (opascal-literal-kind (1- p))) + (pattern (opascal-literal-end-pattern kind))) (or (null kind) ; Non-literals are considered as end points. - (and (delphi-looking-at-string (- p (length pattern)) pattern) - (or (not (delphi-is kind delphi-strings)) + (and (opascal-looking-at-string (- p (length pattern)) pattern) + (or (not (opascal-is kind opascal-strings)) ;; Special case: string delimiters are start/end ambiguous. ;; We have an end only if there is some string content (at ;; least a starting delimiter). - (not (delphi-is-literal-end (1- p))))) + (not (opascal-is-literal-end (1- p))))) ;; Special case: strings cannot span lines. - (and (delphi-is kind delphi-strings) (eq ?\n (char-after (1- p))))))) + (and (opascal-is kind opascal-strings) (eq ?\n (char-after (1- p))))))) -(defun delphi-is-stable-literal (p) +(defun opascal-is-stable-literal (p) ;; True if the point p marks a stable point. That is, a point outside of a ;; literal region, inside of a literal region, or adjacent to completed ;; literal regions. - (let ((at-start (delphi-is-literal-start p)) - (at-end (delphi-is-literal-end p))) + (let ((at-start (opascal-is-literal-start p)) + (at-end (opascal-is-literal-end p))) (or (>= p (point-max)) (and at-start at-end) (and (not at-start) (not at-end) - (eq (delphi-literal-kind (1- p)) (delphi-literal-kind p)))))) + (eq (opascal-literal-kind (1- p)) (opascal-literal-kind p)))))) -(defun delphi-complete-literal (literal-kind limit) +(defun opascal-complete-literal (literal-kind limit) ;; Continues the search for a literal's true end point and returns the ;; point past the end pattern (if found) or the limit (if not found). - (let ((pattern (delphi-literal-stop-pattern literal-kind))) + (let ((pattern (opascal-literal-stop-pattern literal-kind))) (if (not (stringp pattern)) (error "Invalid literal kind %S" literal-kind) ;; Search up to the limit. (re-search-forward pattern limit 'goto-limit-on-fail) (point)))) -(defun delphi-literal-text-properties (kind) +(defun opascal-literal-text-properties (kind) ;; Creates a list of text properties for the literal kind. (if (and (boundp 'font-lock-mode) font-lock-mode) - (list 'token kind 'face (delphi-face-of kind) 'lazy-lock t) + (list 'token kind 'face (opascal-face-of kind) 'lazy-lock t) (list 'token kind))) -(defun delphi-parse-next-literal (limit) +(defun opascal-parse-next-literal (limit) ;; Searches for the next literal region (i.e. comment or string) and sets the ;; the point to its end (or the limit, if not found). The literal region is ;; marked as such with a text property, to speed up tokenizing during face ;; coloring and indentation scanning. (let ((search-start (point))) - (cond ((not (delphi-is-literal-end search-start)) + (cond ((not (opascal-is-literal-end search-start)) ;; We are completing an incomplete literal. - (let ((kind (delphi-literal-kind (1- search-start)))) - (delphi-complete-literal kind limit) - (delphi-set-text-properties - search-start (point) (delphi-literal-text-properties kind)))) + (let ((kind (opascal-literal-kind (1- search-start)))) + (opascal-complete-literal kind limit) + (opascal-set-text-properties + search-start (point) (opascal-literal-text-properties kind)))) ((re-search-forward "\\(//\\)\\|\\({\\)\\|\\((\\*\\)\\|\\('\\)\\|\\(\"\\)" @@ -564,34 +520,34 @@ ((match-beginning 4) 'string) ((match-beginning 5) 'double-quoted-string))) (start (match-beginning 0))) - (delphi-set-text-properties search-start start nil) - (delphi-complete-literal kind limit) - (delphi-set-text-properties - start (point) (delphi-literal-text-properties kind)))) + (opascal-set-text-properties search-start start nil) + (opascal-complete-literal kind limit) + (opascal-set-text-properties + start (point) (opascal-literal-text-properties kind)))) ;; Nothing found. Mark it as a non-literal. - ((delphi-set-text-properties search-start limit nil))) - (delphi-step-progress (point) "Parsing" delphi-parsing-progress-step))) + ((opascal-set-text-properties search-start limit nil))) + (opascal-step-progress (point) "Parsing" opascal-parsing-progress-step))) -(defun delphi-literal-token-at (p) +(defun opascal-literal-token-at (p) ;; Returns the literal token surrounding the point p, or nil if none. - (let ((kind (delphi-literal-kind p))) + (let ((kind (opascal-literal-kind p))) (when kind (let ((start (previous-single-property-change (1+ p) 'token)) (end (next-single-property-change p 'token))) - (delphi-token-of kind (or start (point-min)) (or end (point-max))))))) + (opascal-token-of kind (or start (point-min)) (or end (point-max))))))) -(defun delphi-point-token-at (p kind) +(defun opascal-point-token-at (p kind) ;; Returns the single character token at the point p. - (delphi-token-of kind p (1+ p))) + (opascal-token-of kind p (1+ p))) -(defsubst delphi-char-token-at (p char kind) +(defsubst opascal-char-token-at (p char kind) ;; Returns the token at the point p that describes the specified character. ;; If not actually over such a character, nil is returned. (when (eq char (char-after p)) - (delphi-token-of kind p (1+ p)))) + (opascal-token-of kind p (1+ p)))) -(defun delphi-charset-token-at (p charset kind) +(defun opascal-charset-token-at (p charset kind) ;; Returns the token surrounding point p that contains only members of the ;; character set. (let ((currp (point)) @@ -602,293 +558,293 @@ (setq end (point)) (goto-char (1+ p)) (skip-chars-backward charset) - (setq token (delphi-token-of kind (point) end))) + (setq token (opascal-token-of kind (point) end))) (goto-char currp) token)) -(defun delphi-space-token-at (p) +(defun opascal-space-token-at (p) ;; If point p is surrounded by space characters, then return the token of the ;; contiguous spaces. - (delphi-charset-token-at p delphi-space-chars 'space)) + (opascal-charset-token-at p opascal-space-chars 'space)) -(defun delphi-word-token-at (p) +(defun opascal-word-token-at (p) ;; If point p is over a word (i.e. identifier characters), then return a word ;; token. If the word is actually a keyword, then return the keyword token. - (let ((word (delphi-charset-token-at p delphi-word-chars 'word))) + (let ((word (opascal-charset-token-at p opascal-word-chars 'word))) (when word - (let* ((word-image (downcase (delphi-token-string word))) + (let* ((word-image (downcase (opascal-token-string word))) (keyword (intern-soft word-image))) (when (and (or keyword (string= "nil" word-image)) - (delphi-is keyword delphi-keywords)) - (delphi-set-token-kind word keyword)) + (opascal-is keyword opascal-keywords)) + (opascal-set-token-kind word keyword)) word)))) -(defun delphi-explicit-token-at (p token-string kind) +(defun opascal-explicit-token-at (p token-string kind) ;; If point p is anywhere in the token string then returns the resulting ;; token. - (let ((token (delphi-charset-token-at p token-string kind))) - (when (and token (string= token-string (delphi-token-string token))) + (let ((token (opascal-charset-token-at p token-string kind))) + (when (and token (string= token-string (opascal-token-string token))) token))) -(defun delphi-token-at (p) +(defun opascal-token-at (p) ;; Returns the token from parsing text at point p. (when (and (<= (point-min) p) (<= p (point-max))) - (cond ((delphi-char-token-at p ?\n 'newline)) - - ((delphi-literal-token-at p)) - - ((delphi-space-token-at p)) - - ((delphi-word-token-at p)) - - ((delphi-char-token-at p ?\( 'open-group)) - ((delphi-char-token-at p ?\) 'close-group)) - ((delphi-char-token-at p ?\[ 'open-group)) - ((delphi-char-token-at p ?\] 'close-group)) - ((delphi-char-token-at p ?\; 'semicolon)) - ((delphi-char-token-at p ?. 'dot)) - ((delphi-char-token-at p ?, 'comma)) - ((delphi-char-token-at p ?= 'equals)) - ((delphi-char-token-at p ?+ 'plus)) - ((delphi-char-token-at p ?- 'minus)) - ((delphi-char-token-at p ?* 'times)) - ((delphi-char-token-at p ?/ 'divides)) - ((delphi-char-token-at p ?: 'colon)) - - ((delphi-explicit-token-at p "<>" 'not-equals)) - - ((delphi-point-token-at p 'punctuation))))) - -(defun delphi-current-token () - ;; Returns the delphi source token under the current point. - (delphi-token-at (point))) - -(defun delphi-next-token (token) + (cond ((opascal-char-token-at p ?\n 'newline)) + + ((opascal-literal-token-at p)) + + ((opascal-space-token-at p)) + + ((opascal-word-token-at p)) + + ((opascal-char-token-at p ?\( 'open-group)) + ((opascal-char-token-at p ?\) 'close-group)) + ((opascal-char-token-at p ?\[ 'open-group)) + ((opascal-char-token-at p ?\] 'close-group)) + ((opascal-char-token-at p ?\; 'semicolon)) + ((opascal-char-token-at p ?. 'dot)) + ((opascal-char-token-at p ?, 'comma)) + ((opascal-char-token-at p ?= 'equals)) + ((opascal-char-token-at p ?+ 'plus)) + ((opascal-char-token-at p ?- 'minus)) + ((opascal-char-token-at p ?* 'times)) + ((opascal-char-token-at p ?/ 'divides)) + ((opascal-char-token-at p ?: 'colon)) + + ((opascal-explicit-token-at p "<>" 'not-equals)) + + ((opascal-point-token-at p 'punctuation))))) + +(defun opascal-current-token () + ;; Returns the opascal source token under the current point. + (opascal-token-at (point))) + +(defun opascal-next-token (token) ;; Returns the token after the specified token. (when token - (let ((next (delphi-token-at (delphi-token-end token)))) + (let ((next (opascal-token-at (opascal-token-end token)))) (if next - (delphi-step-progress (delphi-token-start next) "Scanning" - delphi-scanning-progress-step)) + (opascal-step-progress (opascal-token-start next) "Scanning" + opascal-scanning-progress-step)) next))) -(defun delphi-previous-token (token) +(defun opascal-previous-token (token) ;; Returns the token before the specified token. (when token - (let ((previous (delphi-token-at (1- (delphi-token-start token))))) + (let ((previous (opascal-token-at (1- (opascal-token-start token))))) (if previous - (delphi-step-progress (delphi-token-start previous) "Scanning" - delphi-scanning-progress-step)) + (opascal-step-progress (opascal-token-start previous) "Scanning" + opascal-scanning-progress-step)) previous))) -(defun delphi-next-visible-token (token) +(defun opascal-next-visible-token (token) ;; Returns the first non-space token after the specified token. (let (next-token) (while (progn - (setq next-token (delphi-next-token token)) - (delphi-is (delphi-token-kind next-token) '(space newline)))) + (setq next-token (opascal-next-token token)) + (opascal-is (opascal-token-kind next-token) '(space newline)))) next-token)) -(defun delphi-parse-region (from to) +(defun opascal-parse-region (from to) ;; Parses the literal tokens in the region. The point is set to "to". (save-restriction (widen) (goto-char from) (while (< (point) to) - (delphi-parse-next-literal to)))) + (opascal-parse-next-literal to)))) -(defun delphi-parse-region-until-stable (from to) +(defun opascal-parse-region-until-stable (from to) ;; Parses at least the literal tokens in the region. After that, parsing ;; continues as long as obsolete literal regions are encountered. The point ;; is set to the encountered stable point. (save-restriction (widen) - (delphi-parse-region from to) - (while (not (delphi-is-stable-literal (point))) - (delphi-parse-next-literal (point-max))))) + (opascal-parse-region from to) + (while (not (opascal-is-stable-literal (point))) + (opascal-parse-next-literal (point-max))))) -(defun delphi-fontify-region (from to &optional verbose) - ;; Colors the text in the region according to Delphi rules. - (delphi-save-excursion - (delphi-save-state +(defun opascal-fontify-region (from to &optional verbose) + ;; Colors the text in the region according to OPascal rules. + (opascal-save-excursion + (opascal-save-state (let ((p from) - (delphi-verbose verbose) + (opascal-verbose verbose) (token nil)) - (delphi-progress-start) + (opascal-progress-start) (while (< p to) ;; Color the token and move past it. - (setq token (delphi-token-at p)) + (setq token (opascal-token-at p)) (add-text-properties - (delphi-token-start token) (delphi-token-end token) - (list 'face (delphi-face-of (delphi-token-kind token)) 'lazy-lock t)) - (setq p (delphi-token-end token)) - (delphi-step-progress p "Fontifying" delphi-fontifying-progress-step)) - (delphi-progress-done))))) + (opascal-token-start token) (opascal-token-end token) + (list 'face (opascal-face-of (opascal-token-kind token)) 'lazy-lock t)) + (setq p (opascal-token-end token)) + (opascal-step-progress p "Fontifying" opascal-fontifying-progress-step)) + (opascal-progress-done))))) -(defun delphi-after-change (change-start change-end _old-length) +(defun opascal-after-change (change-start change-end _old-length) ;; Called when the buffer has changed. Reparses the changed region. - (unless delphi-ignore-changes - (let ((delphi-ignore-changes t)) ; Prevent recursive calls. - (delphi-save-excursion - (delphi-progress-start) + (unless opascal--ignore-changes + (let ((opascal--ignore-changes t)) ; Prevent recursive calls. + (opascal-save-excursion + (opascal-progress-start) ;; Reparse at least from the token previous to the change to the end of ;; line after the change. - (delphi-parse-region-until-stable - (delphi-token-start (delphi-token-at (1- change-start))) + (opascal-parse-region-until-stable + (opascal-token-start (opascal-token-at (1- change-start))) (progn (goto-char change-end) (end-of-line) (point))) - (delphi-progress-done))))) + (opascal-progress-done))))) -(defun delphi-group-start (from-token) +(defun opascal-group-start (from-token) ;; Returns the token that denotes the start of the ()/[] group. - (let ((token (delphi-previous-token from-token)) + (let ((token (opascal-previous-token from-token)) (token-kind nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; Skip over nested groups. - ((eq 'close-group token-kind) (setq token (delphi-group-start token))) + ((eq 'close-group token-kind) (setq token (opascal-group-start token))) ((eq 'open-group token-kind) (throw 'done token))) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) ;; Start not found. nil))) -(defun delphi-group-end (from-token) +(defun opascal-group-end (from-token) ;; Returns the token that denotes the end of the ()/[] group. - (let ((token (delphi-next-token from-token)) + (let ((token (opascal-next-token from-token)) (token-kind nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; Skip over nested groups. - ((eq 'open-group token-kind) (setq token (delphi-group-end token))) + ((eq 'open-group token-kind) (setq token (opascal-group-end token))) ((eq 'close-group token-kind) (throw 'done token))) - (setq token (delphi-next-token token))) + (setq token (opascal-next-token token))) ;; end not found. nil))) -(defun delphi-indent-of (token &optional offset) +(defun opascal-indent-of (token &optional offset) ;; Returns the start column of the token, plus any offset. - (let ((indent (+ (delphi-column-of (delphi-token-start token)) + (let ((indent (+ (opascal-column-of (opascal-token-start token)) (if offset offset 0)))) - (when delphi-debug - (delphi-debug-log + (when opascal-debug + (opascal-debug-log (concat "\n Indent of: %S %S" "\n column: %d indent: %d offset: %d") - token (delphi-token-string token) - (delphi-column-of (delphi-token-start token)) + token (opascal-token-string token) + (opascal-column-of (opascal-token-start token)) indent (if offset offset 0))) indent)) -(defun delphi-line-indent-of (from-token &optional offset &rest terminators) +(defun opascal-line-indent-of (from-token &optional offset &rest terminators) ;; Returns the column of first non-space character on the token's line, plus ;; any offset. We also stop if one of the terminators or an open ( or [ is ;; encountered. - (let ((token (delphi-previous-token from-token)) + (let ((token (opascal-previous-token from-token)) (last-token from-token) (kind nil)) (catch 'done (while token - (setq kind (delphi-token-kind token)) + (setq kind (opascal-token-kind token)) (cond ;; Skip over ()/[] groups. - ((eq 'close-group kind) (setq token (delphi-group-start token))) + ((eq 'close-group kind) (setq token (opascal-group-start token))) ;; Stop at the beginning of the line or an open group. - ((delphi-is kind '(newline open-group)) (throw 'done nil)) + ((opascal-is kind '(newline open-group)) (throw 'done nil)) ;; Stop at one of the specified terminators. - ((delphi-is kind terminators) (throw 'done nil))) - (unless (delphi-is kind delphi-whitespace) (setq last-token token)) - (setq token (delphi-previous-token token)))) - (delphi-indent-of last-token offset))) + ((opascal-is kind terminators) (throw 'done nil))) + (unless (opascal-is kind opascal-whitespace) (setq last-token token)) + (setq token (opascal-previous-token token)))) + (opascal-indent-of last-token offset))) -(defun delphi-stmt-line-indent-of (from-token &optional offset) - ;; Like `delphi-line-indent-of' except is also stops on a use clause, and +(defun opascal-stmt-line-indent-of (from-token &optional offset) + ;; Like `opascal-line-indent-of' except is also stops on a use clause, and ;; colons that precede statements (i.e. case labels). - (let ((token (delphi-previous-token from-token)) + (let ((token (opascal-previous-token from-token)) (last-token from-token) (kind nil)) (catch 'done (while token - (setq kind (delphi-token-kind token)) + (setq kind (opascal-token-kind token)) (cond ((and (eq 'colon kind) - (delphi-is (delphi-token-kind last-token) - `(,@delphi-block-statements - ,@delphi-expr-statements))) + (opascal-is (opascal-token-kind last-token) + `(,@opascal-block-statements + ,@opascal-expr-statements))) ;; We hit a label followed by a statement. Indent to the statement. (throw 'done nil)) ;; Skip over ()/[] groups. - ((eq 'close-group kind) (setq token (delphi-group-start token))) + ((eq 'close-group kind) (setq token (opascal-group-start token))) - ((delphi-is kind `(newline open-group ,@delphi-use-clauses)) + ((opascal-is kind `(newline open-group ,@opascal-use-clauses)) ;; Stop at the beginning of the line, an open group, or a use clause (throw 'done nil))) - (unless (delphi-is kind delphi-whitespace) (setq last-token token)) - (setq token (delphi-previous-token token)))) - (delphi-indent-of last-token offset))) + (unless (opascal-is kind opascal-whitespace) (setq last-token token)) + (setq token (opascal-previous-token token)))) + (opascal-indent-of last-token offset))) -(defun delphi-open-group-indent (token last-token &optional offset) +(defun opascal-open-group-indent (token last-token &optional offset) ;; Returns the indent relative to an unmatched ( or [. - (when (eq 'open-group (delphi-token-kind token)) + (when (eq 'open-group (opascal-token-kind token)) (if last-token - (delphi-indent-of last-token offset) + (opascal-indent-of last-token offset) ;; There is nothing following the ( or [. Indent from its line. - (delphi-stmt-line-indent-of token delphi-indent-level)))) + (opascal-stmt-line-indent-of token opascal-indent-level)))) -(defun delphi-composite-type-start (token last-token) +(defun opascal-composite-type-start (token last-token) ;; Returns true (actually the last-token) if the pair equals (= class), (= ;; dispinterface), (= interface), (= object), or (= record), and nil ;; otherwise. - (if (and (eq 'equals (delphi-token-kind token)) - (delphi-is (delphi-token-kind last-token) delphi-composite-types)) + (if (and (eq 'equals (opascal-token-kind token)) + (opascal-is (opascal-token-kind last-token) opascal-composite-types)) last-token)) -(defun delphi-is-simple-class-type (at-token limit-token) +(defun opascal-is-simple-class-type (at-token limit-token) ;; True if at-token is the start of a simple class type. E.g. ;; class of TClass; ;; class (TBaseClass); ;; class; - (when (delphi-is (delphi-token-kind at-token) delphi-class-types) + (when (opascal-is (opascal-token-kind at-token) opascal-class-types) (catch 'done ;; Scan until the semi colon. - (let ((token (delphi-next-token at-token)) + (let ((token (opascal-next-token at-token)) (token-kind nil) - (limit (delphi-token-start limit-token))) - (while (and token (<= (delphi-token-start token) limit)) - (setq token-kind (delphi-token-kind token)) + (limit (opascal-token-start limit-token))) + (while (and token (<= (opascal-token-start token) limit)) + (setq token-kind (opascal-token-kind token)) (cond ;; A semicolon delimits the search. ((eq 'semicolon token-kind) (throw 'done token)) ;; Skip over the inheritance list. - ((eq 'open-group token-kind) (setq token (delphi-group-end token))) + ((eq 'open-group token-kind) (setq token (opascal-group-end token))) ;; Only allow "of" and whitespace, and an identifier - ((delphi-is token-kind `(of word ,@delphi-whitespace))) + ((opascal-is token-kind `(of word ,@opascal-whitespace))) ;; Otherwise we are not in a simple class declaration. ((throw 'done nil))) - (setq token (delphi-next-token token))))))) + (setq token (opascal-next-token token))))))) -(defun delphi-block-start (from-token &optional stop-on-class) +(defun opascal-block-start (from-token &optional stop-on-class) ;; Returns the token that denotes the start of the block. - (let ((token (delphi-previous-token from-token)) + (let ((token (opascal-previous-token from-token)) (last-token nil) (token-kind nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; Skip over nested blocks. - ((delphi-is token-kind delphi-end-block-statements) - (setq token (delphi-block-start token))) + ((opascal-is token-kind opascal-end-block-statements) + (setq token (opascal-block-start token))) ;; Regular block start found. - ((delphi-is token-kind delphi-block-statements) + ((opascal-is token-kind opascal-block-statements) (throw 'done ;; As a special case, when a "case" block appears ;; within a record declaration (to denote a variant @@ -896,42 +852,42 @@ ;; the enclosing block. (if (eq 'case token-kind) (let ((enclosing-token - (delphi-block-start token + (opascal-block-start token 'stop-on-class))) (if (eq 'record - (delphi-token-kind enclosing-token)) + (opascal-token-kind enclosing-token)) (if stop-on-class enclosing-token - (delphi-previous-token enclosing-token)) + (opascal-previous-token enclosing-token)) token)) token))) ;; A class/record start also begins a block. - ((delphi-composite-type-start token last-token) + ((opascal-composite-type-start token last-token) (throw 'done (if stop-on-class last-token token))) ) - (unless (delphi-is token-kind delphi-whitespace) + (unless (opascal-is token-kind opascal-whitespace) (setq last-token token)) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) ;; Start not found. nil))) -(defun delphi-else-start (from-else) +(defun opascal-else-start (from-else) ;; Returns the token of the if or case statement. - (let ((token (delphi-previous-token from-else)) + (let ((token (opascal-previous-token from-else)) (token-kind nil) (semicolon-count 0)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; Skip over nested groups. - ((eq 'close-group token-kind) (setq token (delphi-group-start token))) + ((eq 'close-group token-kind) (setq token (opascal-group-start token))) ;; Skip over any nested blocks. - ((delphi-is token-kind delphi-end-block-statements) - (setq token (delphi-block-start token))) + ((opascal-is token-kind opascal-end-block-statements) + (setq token (opascal-block-start token))) ((eq 'semicolon token-kind) ;; Semicolon means we are looking for an enclosing if, unless we @@ -947,151 +903,151 @@ ((eq 'case token-kind) ;; We have hit a case statement start. (throw 'done token))) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) ;; No if or case statement found. nil))) -(defun delphi-comment-content-start (comment) +(defun opascal-comment-content-start (comment) ;; Returns the point of the first non-space character in the comment. - (let ((kind (delphi-token-kind comment))) - (when (delphi-is kind delphi-comments) - (delphi-save-excursion - (goto-char (+ (delphi-token-start comment) - (length (delphi-literal-start-pattern kind)))) - (skip-chars-forward delphi-space-chars) + (let ((kind (opascal-token-kind comment))) + (when (opascal-is kind opascal-comments) + (opascal-save-excursion + (goto-char (+ (opascal-token-start comment) + (length (opascal-literal-start-pattern kind)))) + (skip-chars-forward opascal-space-chars) (point))))) -(defun delphi-comment-block-start (comment) +(defun opascal-comment-block-start (comment) ;; Returns the starting comment token of a contiguous // comment block. If ;; the comment is multiline (i.e. {...} or (*...*)), the original comment is ;; returned. - (if (not (eq 'comment-single-line (delphi-token-kind comment))) + (if (not (eq 'comment-single-line (opascal-token-kind comment))) comment ;; Scan until we run out of // comments. (let ((prev-comment comment) (start-comment comment)) - (while (let ((kind (delphi-token-kind prev-comment))) + (while (let ((kind (opascal-token-kind prev-comment))) (cond ((eq kind 'space)) ((eq kind 'comment-single-line) (setq start-comment prev-comment)) (t nil))) - (setq prev-comment (delphi-previous-token prev-comment))) + (setq prev-comment (opascal-previous-token prev-comment))) start-comment))) -(defun delphi-comment-block-end (comment) +(defun opascal-comment-block-end (comment) ;; Returns the end comment token of a contiguous // comment block. If the ;; comment is multiline (i.e. {...} or (*...*)), the original comment is ;; returned. - (if (not (eq 'comment-single-line (delphi-token-kind comment))) + (if (not (eq 'comment-single-line (opascal-token-kind comment))) comment ;; Scan until we run out of // comments. (let ((next-comment comment) (end-comment comment)) - (while (let ((kind (delphi-token-kind next-comment))) + (while (let ((kind (opascal-token-kind next-comment))) (cond ((eq kind 'space)) ((eq kind 'comment-single-line) (setq end-comment next-comment)) (t nil))) - (setq next-comment (delphi-next-token next-comment))) + (setq next-comment (opascal-next-token next-comment))) end-comment))) -(defun delphi-on-first-comment-line (comment) +(defun opascal-on-first-comment-line (comment) ;; Returns true if the current point is on the first line of the comment. (save-excursion - (let ((comment-start (delphi-token-start comment)) + (let ((comment-start (opascal-token-start comment)) (current-point (point))) (goto-char comment-start) (end-of-line) (and (<= comment-start current-point) (<= current-point (point)))))) -(defun delphi-comment-indent-of (comment) +(defun opascal-comment-indent-of (comment) ;; Returns the correct indentation for the comment. - (let ((start-comment (delphi-comment-block-start comment))) + (let ((start-comment (opascal-comment-block-start comment))) (if (and (eq start-comment comment) - (delphi-on-first-comment-line comment)) + (opascal-on-first-comment-line comment)) ;; Indent as a statement. - (delphi-enclosing-indent-of comment) + (opascal-enclosing-indent-of comment) (save-excursion - (let ((kind (delphi-token-kind comment))) + (let ((kind (opascal-token-kind comment))) (beginning-of-line) (cond ((eq 'comment-single-line kind) ;; Indent to the first comment in the // block. - (delphi-indent-of start-comment)) + (opascal-indent-of start-comment)) - ((looking-at (concat delphi-leading-spaces-re - (delphi-literal-stop-pattern kind))) + ((looking-at (concat opascal-leading-spaces-re + (opascal-literal-stop-pattern kind))) ;; Indent multi-line comment terminators to the comment start. - (delphi-indent-of comment)) + (opascal-indent-of comment)) ;; Indent according to the comment's content start. - ((delphi-column-of (delphi-comment-content-start comment))))))) + ((opascal-column-of (opascal-comment-content-start comment))))))) )) -(defun delphi-is-use-clause-end (at-token last-token last-colon from-kind) +(defun opascal-is-use-clause-end (at-token last-token last-colon from-kind) ;; True if we are after the end of a uses type clause. (when (and last-token (not last-colon) - (eq 'comma (delphi-token-kind at-token)) + (eq 'comma (opascal-token-kind at-token)) (eq 'semicolon from-kind)) ;; Scan for the uses statement, just to be sure. - (let ((token (delphi-previous-token at-token)) + (let ((token (opascal-previous-token at-token)) (token-kind nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) - (cond ((delphi-is token-kind delphi-use-clauses) + (setq token-kind (opascal-token-kind token)) + (cond ((opascal-is token-kind opascal-use-clauses) (throw 'done t)) ;; Whitespace, identifiers, strings, "in" keyword, and commas ;; are allowed in use clauses. - ((or (delphi-is token-kind '(word comma in newline)) - (delphi-is token-kind delphi-whitespace) - (delphi-is token-kind delphi-strings))) + ((or (opascal-is token-kind '(word comma in newline)) + (opascal-is token-kind opascal-whitespace) + (opascal-is token-kind opascal-strings))) ;; Nothing else is. ((throw 'done nil))) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) nil)))) -(defun delphi-is-block-after-expr-statement (token) +(defun opascal-is-block-after-expr-statement (token) ;; Returns true if we have a block token trailing an expression delimiter (of ;; presumably an expression statement). - (when (delphi-is (delphi-token-kind token) delphi-block-statements) - (let ((previous (delphi-previous-token token)) + (when (opascal-is (opascal-token-kind token) opascal-block-statements) + (let ((previous (opascal-previous-token token)) (previous-kind nil)) (while (progn - (setq previous-kind (delphi-token-kind previous)) + (setq previous-kind (opascal-token-kind previous)) (eq previous-kind 'space)) - (setq previous (delphi-previous-token previous))) - (or (delphi-is previous-kind delphi-expr-delimiters) + (setq previous (opascal-previous-token previous))) + (or (opascal-is previous-kind opascal-expr-delimiters) (eq previous-kind 'else))))) -(defun delphi-previous-indent-of (from-token) +(defun opascal-previous-indent-of (from-token) ;; Returns the indentation of the previous statement of the token. - (let ((token (delphi-previous-token from-token)) + (let ((token (opascal-previous-token from-token)) (token-kind nil) - (from-kind (delphi-token-kind from-token)) + (from-kind (opascal-token-kind from-token)) (last-colon nil) (last-of nil) (last-token nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; An open ( or [ always is an indent point. ((eq 'open-group token-kind) - (throw 'done (delphi-open-group-indent token last-token))) + (throw 'done (opascal-open-group-indent token last-token))) ;; Skip over any ()/[] groups. - ((eq 'close-group token-kind) (setq token (delphi-group-start token))) + ((eq 'close-group token-kind) (setq token (opascal-group-start token))) - ((delphi-is token-kind delphi-end-block-statements) - (if (eq 'newline (delphi-token-kind (delphi-previous-token token))) + ((opascal-is token-kind opascal-end-block-statements) + (if (eq 'newline (opascal-token-kind (opascal-previous-token token))) ;; We can stop at an end token that is right up against the ;; margin. (throw 'done 0) ;; Otherwise, skip over any nested blocks. - (setq token (delphi-block-start token)))) + (setq token (opascal-block-start token)))) ;; Special case: if we encounter a ", word;" then we assume that we ;; are in some kind of uses clause, and thus indent to column 0. This @@ -1102,19 +1058,19 @@ ;; someUnit, ;; someOtherUnit; ;; // this should be at column 0! - ((delphi-is-use-clause-end token last-token last-colon from-kind) + ((opascal-is-use-clause-end token last-token last-colon from-kind) (throw 'done 0)) ;; A previous terminator means we can stop. If we are on a directive, ;; however, then we are not actually encountering a new statement. ((and last-token - (delphi-is token-kind delphi-previous-terminators) - (not (delphi-is (delphi-token-kind last-token) - delphi-directives))) - (throw 'done (delphi-stmt-line-indent-of last-token 0))) + (opascal-is token-kind opascal-previous-terminators) + (not (opascal-is (opascal-token-kind last-token) + opascal-directives))) + (throw 'done (opascal-stmt-line-indent-of last-token 0))) ;; Ignore whitespace. - ((delphi-is token-kind delphi-whitespace)) + ((opascal-is token-kind opascal-whitespace)) ;; Remember any "of" we encounter, since that affects how we ;; indent to a case statement within a record declaration @@ -1132,61 +1088,61 @@ ;; specially. ((eq 'case token-kind) (throw 'done - (if last-colon (delphi-line-indent-of last-colon) - (delphi-line-indent-of token delphi-case-label-indent)))) + (if last-colon (opascal-line-indent-of last-colon) + (opascal-line-indent-of token opascal-case-label-indent)))) ;; If we are in a use clause then commas mark an enclosing rather than ;; a previous statement. - ((delphi-is token-kind delphi-use-clauses) + ((opascal-is token-kind opascal-use-clauses) (throw 'done (if (eq 'comma from-kind) (if last-token ;; Indent to first unit in use clause. - (delphi-indent-of last-token) + (opascal-indent-of last-token) ;; Indent from use clause keyword. - (delphi-line-indent-of token delphi-indent-level)) + (opascal-line-indent-of token opascal-indent-level)) ;; Indent to use clause keyword. - (delphi-line-indent-of token)))) + (opascal-line-indent-of token)))) ;; Assembly sections always indent in from the asm keyword. ((eq token-kind 'asm) - (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) + (throw 'done (opascal-stmt-line-indent-of token opascal-indent-level))) ;; An enclosing statement delimits a previous statement. ;; We try to use the existing indent of the previous statement, ;; otherwise we calculate from the enclosing statement. - ((delphi-is token-kind delphi-previous-enclosing-statements) + ((opascal-is token-kind opascal-previous-enclosing-statements) (throw 'done (if last-token ;; Otherwise indent to the last token - (delphi-line-indent-of last-token) + (opascal-line-indent-of last-token) ;; Just indent from the enclosing keyword - (delphi-line-indent-of token delphi-indent-level)))) + (opascal-line-indent-of token opascal-indent-level)))) ;; A class or record declaration also delimits a previous statement. - ((delphi-composite-type-start token last-token) + ((opascal-composite-type-start token last-token) (throw 'done - (if (delphi-is-simple-class-type last-token from-token) + (if (opascal-is-simple-class-type last-token from-token) ;; c = class; or c = class of T; are previous statements. - (delphi-line-indent-of token) + (opascal-line-indent-of token) ;; Otherwise c = class ... or r = record ... are enclosing ;; statements. - (delphi-line-indent-of last-token delphi-indent-level)))) + (opascal-line-indent-of last-token opascal-indent-level)))) ;; We have a definite previous statement delimiter. - ((delphi-is token-kind delphi-previous-statements) - (throw 'done (delphi-stmt-line-indent-of token 0))) + ((opascal-is token-kind opascal-previous-statements) + (throw 'done (opascal-stmt-line-indent-of token 0))) ) - (unless (delphi-is token-kind delphi-whitespace) + (unless (opascal-is token-kind opascal-whitespace) (setq last-token token)) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) ;; We ran out of tokens. Indent to column 0. 0))) -(defun delphi-section-indent-of (section-token) +(defun opascal-section-indent-of (section-token) ;; Returns the indentation appropriate for begin/var/const/type/label ;; tokens. - (let* ((token (delphi-previous-token section-token)) + (let* ((token (opascal-previous-token section-token)) (token-kind nil) (last-token nil) (nested-block-count 0) @@ -1194,22 +1150,22 @@ (last-terminator nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; Always stop at unmatched ( or [. ((eq token-kind 'open-group) - (throw 'done (delphi-open-group-indent token last-token))) + (throw 'done (opascal-open-group-indent token last-token))) ;; Skip over any ()/[] groups. - ((eq 'close-group token-kind) (setq token (delphi-group-start token))) + ((eq 'close-group token-kind) (setq token (opascal-group-start token))) - ((delphi-is token-kind delphi-end-block-statements) - (if (eq 'newline (delphi-token-kind (delphi-previous-token token))) + ((opascal-is token-kind opascal-end-block-statements) + (if (eq 'newline (opascal-token-kind (opascal-previous-token token))) ;; We can stop at an end token that is right up against the ;; margin. (throw 'done 0) ;; Otherwise, skip over any nested blocks. - (setq token (delphi-block-start token) + (setq token (opascal-block-start token) nested-block-count (1+ nested-block-count)))) ;; Remember if we have encountered any forward routine declarations. @@ -1217,7 +1173,7 @@ (setq nested-block-count (1+ nested-block-count))) ;; Mark the completion of a nested routine traversal. - ((and (delphi-is token-kind delphi-routine-statements) + ((and (opascal-is token-kind opascal-routine-statements) (> nested-block-count 0)) (setq nested-block-count (1- nested-block-count))) @@ -1225,50 +1181,50 @@ ((eq 'semicolon token-kind) (setq last-terminator token)) ;; Remember if we have encountered any expression delimiters. - ((delphi-is token-kind delphi-expr-delimiters) + ((opascal-is token-kind opascal-expr-delimiters) (setq expr-delimited token)) ;; Enclosing body statements are delimiting. We indent the compound ;; bodies specially. ((and (not last-terminator) - (delphi-is token-kind delphi-body-statements)) + (opascal-is token-kind opascal-body-statements)) (throw 'done - (delphi-stmt-line-indent-of token delphi-compound-block-indent))) + (opascal-stmt-line-indent-of token opascal-compound-block-indent))) ;; An enclosing ":" means a label. ((and (eq 'colon token-kind) - (delphi-is (delphi-token-kind section-token) - delphi-block-statements) + (opascal-is (opascal-token-kind section-token) + opascal-block-statements) (not last-terminator) (not expr-delimited) - (not (eq 'equals (delphi-token-kind last-token)))) + (not (eq 'equals (opascal-token-kind last-token)))) (throw 'done - (delphi-stmt-line-indent-of token delphi-indent-level))) + (opascal-stmt-line-indent-of token opascal-indent-level))) ;; Block and mid block tokens are always enclosing - ((delphi-is token-kind delphi-begin-enclosing-tokens) + ((opascal-is token-kind opascal-begin-enclosing-tokens) (throw 'done - (delphi-stmt-line-indent-of token delphi-indent-level))) + (opascal-stmt-line-indent-of token opascal-indent-level))) ;; Declaration sections and routines are delimiters, unless they ;; are part of a nested routine. - ((and (delphi-is token-kind delphi-decl-delimiters) + ((and (opascal-is token-kind opascal-decl-delimiters) (= 0 nested-block-count)) - (throw 'done (delphi-line-indent-of token 0))) + (throw 'done (opascal-line-indent-of token 0))) ;; Unit statements mean we indent right to the left. - ((delphi-is token-kind delphi-unit-statements) (throw 'done 0)) + ((opascal-is token-kind opascal-unit-statements) (throw 'done 0)) ) - (unless (delphi-is token-kind delphi-whitespace) + (unless (opascal-is token-kind opascal-whitespace) (setq last-token token)) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) ;; We ran out of tokens. Indent to column 0. 0))) -(defun delphi-enclosing-indent-of (from-token) +(defun opascal-enclosing-indent-of (from-token) ;; Returns the indentation offset from the enclosing statement of the token. - (let ((token (delphi-previous-token from-token)) - (from-kind (delphi-token-kind from-token)) + (let ((token (opascal-previous-token from-token)) + (from-kind (opascal-token-kind from-token)) (token-kind nil) (stmt-start nil) (last-token nil) @@ -1277,51 +1233,51 @@ (expr-delimited nil)) (catch 'done (while token - (setq token-kind (delphi-token-kind token)) + (setq token-kind (opascal-token-kind token)) (cond ;; An open ( or [ always is an indent point. ((eq 'open-group token-kind) (throw 'done - (delphi-open-group-indent + (opascal-open-group-indent token last-token - (if (delphi-is from-kind delphi-binary-ops) + (if (opascal-is from-kind opascal-binary-ops) ;; Keep binary operations aligned with the open group. 0 - delphi-indent-level)))) + opascal-indent-level)))) ;; Skip over any ()/[] groups. - ((eq 'close-group token-kind) (setq token (delphi-group-start token))) + ((eq 'close-group token-kind) (setq token (opascal-group-start token))) ;; Skip over any nested blocks. - ((delphi-is token-kind delphi-end-block-statements) - (setq token (delphi-block-start token))) + ((opascal-is token-kind opascal-end-block-statements) + (setq token (opascal-block-start token))) ;; An expression delimiter affects indentation depending on whether ;; the point is before or after it. Remember that we encountered one. ;; Also remember the last encountered token, since if it exists it ;; should be the actual indent point. - ((delphi-is token-kind delphi-expr-delimiters) + ((opascal-is token-kind opascal-expr-delimiters) (setq expr-delimited token stmt-start last-token)) ;; With a non-delimited expression statement we indent after the ;; statement's keyword, unless we are on the delimiter itself. ((and (not expr-delimited) - (delphi-is token-kind delphi-expr-statements)) + (opascal-is token-kind opascal-expr-statements)) (throw 'done - (cond ((delphi-is from-kind delphi-expr-delimiters) + (cond ((opascal-is from-kind opascal-expr-delimiters) ;; We are indenting a delimiter. Indent to the statement. - (delphi-stmt-line-indent-of token 0)) + (opascal-stmt-line-indent-of token 0)) - ((and last-token (delphi-is from-kind delphi-binary-ops)) + ((and last-token (opascal-is from-kind opascal-binary-ops)) ;; Align binary ops with the expression. - (delphi-indent-of last-token)) + (opascal-indent-of last-token)) (last-token ;; Indent in from the expression. - (delphi-indent-of last-token delphi-indent-level)) + (opascal-indent-of last-token opascal-indent-level)) ;; Indent in from the statement's keyword. - ((delphi-indent-of token delphi-indent-level))))) + ((opascal-indent-of token opascal-indent-level))))) ;; A delimited case statement indents the label according to ;; a special rule. @@ -1330,72 +1286,72 @@ (if stmt-start ;; We are not actually indenting to the case statement, ;; but are within a label expression. - (delphi-stmt-line-indent-of - stmt-start delphi-indent-level) + (opascal-stmt-line-indent-of + stmt-start opascal-indent-level) ;; Indent from the case keyword. - (delphi-stmt-line-indent-of - token delphi-case-label-indent)))) + (opascal-stmt-line-indent-of + token opascal-case-label-indent)))) ;; Body expression statements are enclosing. Indent from the ;; statement's keyword, unless we have a non-block statement following ;; it. - ((delphi-is token-kind delphi-body-expr-statements) + ((opascal-is token-kind opascal-body-expr-statements) (throw 'done - (delphi-stmt-line-indent-of - (or stmt-start token) delphi-indent-level))) + (opascal-stmt-line-indent-of + (or stmt-start token) opascal-indent-level))) ;; An else statement is enclosing, but it doesn't have an expression. ;; Thus we take into account last-token instead of stmt-start. ((eq 'else token-kind) - (throw 'done (delphi-stmt-line-indent-of - (or last-token token) delphi-indent-level))) + (throw 'done (opascal-stmt-line-indent-of + (or last-token token) opascal-indent-level))) ;; We indent relative to an enclosing declaration section. - ((delphi-is token-kind delphi-decl-sections) - (throw 'done (delphi-indent-of (if last-token last-token token) - delphi-indent-level))) + ((opascal-is token-kind opascal-decl-sections) + (throw 'done (opascal-indent-of (if last-token last-token token) + opascal-indent-level))) ;; In unit sections we indent right to the left. - ((delphi-is token-kind delphi-unit-sections) + ((opascal-is token-kind opascal-unit-sections) (throw 'done ;; Handle specially the case of "interface", which can be used ;; to start either a unit section or an interface definition. - (if (delphi-is token-kind delphi-interface-types) + (if (opascal-is token-kind opascal-interface-types) (progn ;; Find the previous non-whitespace token. (while (progn (setq last-token token - token (delphi-previous-token token) - token-kind (delphi-token-kind token)) + token (opascal-previous-token token) + token-kind (opascal-token-kind token)) (and token - (delphi-is token-kind - delphi-whitespace)))) + (opascal-is token-kind + opascal-whitespace)))) ;; If this token is an equals sign, "interface" is being ;; used to start an interface definition and we should ;; treat it as a composite type; otherwise, we should ;; consider it the start of a unit section. (if (and token (eq token-kind 'equals)) - (delphi-line-indent-of last-token - delphi-indent-level) + (opascal-line-indent-of last-token + opascal-indent-level) 0)) 0))) ;; A previous terminator means we can stop. - ((delphi-is token-kind delphi-previous-terminators) + ((opascal-is token-kind opascal-previous-terminators) (throw 'done (cond ((and last-token (eq 'comma token-kind) - (delphi-is from-kind delphi-binary-ops)) + (opascal-is from-kind opascal-binary-ops)) ;; Align binary ops with the expression. - (delphi-indent-of last-token)) + (opascal-indent-of last-token)) (last-token ;; Indent in from the expression. - (delphi-indent-of last-token delphi-indent-level)) + (opascal-indent-of last-token opascal-indent-level)) ;; No enclosing expression; use the previous statement's ;; indent. - ((delphi-previous-indent-of token))))) + ((opascal-previous-indent-of token))))) ;; A block statement after an expression delimiter has its start ;; column as the expression statement. E.g. @@ -1404,37 +1360,37 @@ ;; //... ;; end; ;; Remember it for when we encounter the expression statement start. - ((delphi-is-block-after-expr-statement token) + ((opascal-is-block-after-expr-statement token) (throw 'done - (cond (last-token (delphi-indent-of last-token delphi-indent-level)) + (cond (last-token (opascal-indent-of last-token opascal-indent-level)) - ((+ (delphi-section-indent-of token) delphi-indent-level))))) + ((+ (opascal-section-indent-of token) opascal-indent-level))))) ;; Assembly sections always indent in from the asm keyword. ((eq token-kind 'asm) - (throw 'done (delphi-stmt-line-indent-of token delphi-indent-level))) + (throw 'done (opascal-stmt-line-indent-of token opascal-indent-level))) ;; Stop at an enclosing statement and indent from it. - ((delphi-is token-kind delphi-enclosing-statements) - (throw 'done (delphi-stmt-line-indent-of - (or last-token token) delphi-indent-level))) + ((opascal-is token-kind opascal-enclosing-statements) + (throw 'done (opascal-stmt-line-indent-of + (or last-token token) opascal-indent-level))) ;; A class/record declaration is also enclosing. - ((delphi-composite-type-start token last-token) + ((opascal-composite-type-start token last-token) (throw 'done - (delphi-line-indent-of last-token delphi-indent-level))) + (opascal-line-indent-of last-token opascal-indent-level))) ;; A ":" we indent relative to its line beginning. If we are in a ;; parameter list, then stop also if we hit a ";". ((and (eq token-kind 'colon) (not expr-delimited) - (not (delphi-is from-kind delphi-expr-delimiters)) + (not (opascal-is from-kind opascal-expr-delimiters)) (not equals-encountered) (not (eq from-kind 'equals))) (throw 'done (if last-token - (delphi-indent-of last-token delphi-indent-level) - (delphi-line-indent-of token delphi-indent-level 'semicolon)))) + (opascal-indent-of last-token opascal-indent-level) + (opascal-line-indent-of token opascal-indent-level 'semicolon)))) ;; If the ":" was not processed above and we have token after the "=", ;; then indent from the "=". Ignore :=, however. @@ -1449,88 +1405,88 @@ ;; + 2; ;; which doesn't look right. ;;;; Align binary ops with the before token. - ;;((delphi-is from-kind delphi-binary-ops) - ;;(throw 'done (delphi-indent-of before-equals 0))) + ;;((opascal-is from-kind opascal-binary-ops) + ;;(throw 'done (opascal-indent-of before-equals 0))) ;; Assignments (:=) we skip over to get a normal indent. - ((eq (delphi-token-kind last-token) 'equals)) + ((eq (opascal-token-kind last-token) 'equals)) ;; Otherwise indent in from the equals. ((throw 'done - (delphi-indent-of before-equals delphi-indent-level))))) + (opascal-indent-of before-equals opascal-indent-level))))) ;; Remember any "=" we encounter if it has not already been processed. ((eq token-kind 'equals) (setq equals-encountered token before-equals last-token)) ) - (unless (delphi-is token-kind delphi-whitespace) + (unless (opascal-is token-kind opascal-whitespace) (setq last-token token)) - (setq token (delphi-previous-token token))) + (setq token (opascal-previous-token token))) ;; We ran out of tokens. Indent to column 0. 0))) -(defun delphi-corrected-indentation () +(defun opascal-corrected-indentation () ;; Returns the corrected indentation for the current line. - (delphi-save-excursion - (delphi-progress-start) + (opascal-save-excursion + (opascal-progress-start) ;; Move to the first token on the line. (beginning-of-line) - (skip-chars-forward delphi-space-chars) - (let* ((token (delphi-current-token)) - (token-kind (delphi-token-kind token)) + (skip-chars-forward opascal-space-chars) + (let* ((token (opascal-current-token)) + (token-kind (opascal-token-kind token)) (indent (cond ((eq 'close-group token-kind) ;; Indent to the matching start ( or [. - (delphi-indent-of (delphi-group-start token))) - - ((delphi-is token-kind delphi-unit-statements) 0) - - ((delphi-is token-kind delphi-comments) + (opascal-indent-of (opascal-group-start token))) + + ((opascal-is token-kind opascal-unit-statements) 0) + + ((opascal-is token-kind opascal-comments) ;; In a comment. - (delphi-comment-indent-of token)) + (opascal-comment-indent-of token)) - ((delphi-is token-kind delphi-decl-matchers) + ((opascal-is token-kind opascal-decl-matchers) ;; Use a previous section/routine's indent. - (delphi-section-indent-of token)) + (opascal-section-indent-of token)) - ((delphi-is token-kind delphi-match-block-statements) + ((opascal-is token-kind opascal-match-block-statements) ;; Use the block's indentation. (let ((block-start - (delphi-block-start token 'stop-on-class))) + (opascal-block-start token 'stop-on-class))) (cond ;; When trailing a body statement, indent to ;; the statement's keyword. - ((delphi-is-block-after-expr-statement block-start) - (delphi-section-indent-of block-start)) + ((opascal-is-block-after-expr-statement block-start) + (opascal-section-indent-of block-start)) ;; Otherwise just indent to the block start. - ((delphi-stmt-line-indent-of block-start 0))))) + ((opascal-stmt-line-indent-of block-start 0))))) ((eq 'else token-kind) ;; Find the start of the if or case statement. - (delphi-stmt-line-indent-of (delphi-else-start token) 0)) + (opascal-stmt-line-indent-of (opascal-else-start token) 0)) ;; Otherwise indent in from enclosing statement. - ((delphi-enclosing-indent-of - (if token token (delphi-token-at (1- (point))))))))) - (delphi-progress-done) + ((opascal-enclosing-indent-of + (if token token (opascal-token-at (1- (point))))))))) + (opascal-progress-done) indent))) -(defun delphi-indent-line () +(defun opascal-indent-line () "Indent the current line according to the current language construct. If before the indent, the point is moved to the indent." (interactive) - (delphi-save-match-data + (save-match-data (let ((marked-point (point-marker)) ; Maintain our position reliably. (line-start nil) (old-indent 0) (new-indent 0)) (beginning-of-line) (setq line-start (point)) - (skip-chars-forward delphi-space-chars) + (skip-chars-forward opascal-space-chars) (setq old-indent (current-column)) - (setq new-indent (delphi-corrected-indentation)) + (setq new-indent (opascal-corrected-indentation)) (if (< marked-point (point)) ;; If before the indent column, then move to it. (set-marker marked-point (point))) @@ -1542,17 +1498,17 @@ (goto-char marked-point) (set-marker marked-point nil)))) -(defvar delphi-mode-abbrev-table nil - "Abbrev table in use in Delphi mode buffers.") -(define-abbrev-table 'delphi-mode-abbrev-table ()) +(defvar opascal-mode-abbrev-table nil + "Abbrev table in use in OPascal mode buffers.") +(define-abbrev-table 'opascal-mode-abbrev-table ()) -(defmacro delphi-ensure-buffer (buffer-var buffer-name) +(defmacro opascal-ensure-buffer (buffer-var buffer-name) ;; Ensures there exists a buffer of the specified name in the specified ;; variable. `(when (not (buffer-live-p ,buffer-var)) (setq ,buffer-var (get-buffer-create ,buffer-name)))) -(defun delphi-log-msg (to-buffer the-msg) +(defun opascal-log-msg (to-buffer the-msg) ;; Writes a message to the end of the specified buffer. (with-current-buffer to-buffer (save-selected-window @@ -1563,176 +1519,160 @@ ;; Debugging helpers: -(defvar delphi-debug-buffer nil - "Buffer to write Delphi mode debug messages to. Created on demand.") +(defvar opascal-debug-buffer nil + "Buffer to write OPascal mode debug messages to. Created on demand.") -(defun delphi-debug-log (format-string &rest args) +(defun opascal-debug-log (format-string &rest args) ;; Writes a message to the log buffer. - (when delphi-debug - (delphi-ensure-buffer delphi-debug-buffer "*Delphi Debug Log*") - (delphi-log-msg delphi-debug-buffer + (when opascal-debug + (opascal-ensure-buffer opascal-debug-buffer "*OPascal Debug Log*") + (opascal-log-msg opascal-debug-buffer (concat (format-time-string "%H:%M:%S " (current-time)) (apply #'format (cons format-string args)) "\n")))) -(defun delphi-debug-token-string (token) - (let* ((image (delphi-token-string token)) +(defun opascal-debug-token-string (token) + (let* ((image (opascal-token-string token)) (has-newline (string-match "^\\([^\n]*\\)\n\\(.+\\)?$" image))) (when has-newline (setq image (concat (match-string 1 image) (if (match-beginning 2) "...")))) image)) -(defun delphi-debug-show-current-token () +(defun opascal-debug-show-current-token () (interactive) - (let ((token (delphi-current-token))) - (delphi-debug-log "Token: %S %S" token (delphi-debug-token-string token)))) + (let ((token (opascal-current-token))) + (opascal-debug-log "Token: %S %S" token (opascal-debug-token-string token)))) -(defun delphi-debug-goto-point (p) +(defun opascal-debug-goto-point (p) (interactive "NGoto char: ") (goto-char p)) -(defun delphi-debug-goto-next-token () +(defun opascal-debug-goto-next-token () (interactive) - (goto-char (delphi-token-start (delphi-next-token (delphi-current-token))))) + (goto-char (opascal-token-start (opascal-next-token (opascal-current-token))))) -(defun delphi-debug-goto-previous-token () +(defun opascal-debug-goto-previous-token () (interactive) (goto-char - (delphi-token-start (delphi-previous-token (delphi-current-token))))) - -(defun delphi-debug-show-current-string (from to) - (interactive "r") - (delphi-debug-log "String: %S" (buffer-substring from to))) - -(defun delphi-debug-show-is-stable () - (interactive) - (delphi-debug-log "stable: %S prev: %S next: %S" - (delphi-is-stable-literal (point)) - (delphi-literal-kind (1- (point))) - (delphi-literal-kind (point)))) - -(defun delphi-debug-unparse-buffer () - (interactive) - (delphi-set-text-properties (point-min) (point-max) nil)) - -(defun delphi-debug-parse-region (from to) - (interactive "r") - (let ((delphi-verbose t)) - (delphi-save-excursion - (delphi-progress-start) - (delphi-parse-region from to) - (delphi-progress-done "Parsing done")))) - -(defun delphi-debug-parse-window () - (interactive) - (delphi-debug-parse-region (window-start) (window-end))) - -(defun delphi-debug-parse-buffer () - (interactive) - (delphi-debug-parse-region (point-min) (point-max))) - -(defun delphi-debug-fontify-window () - (interactive) - (delphi-fontify-region (window-start) (window-end) t)) - -(defun delphi-debug-fontify-buffer () - (interactive) - (delphi-fontify-region (point-min) (point-max) t)) - -(defun delphi-debug-tokenize-region (from to) - (interactive) - (delphi-save-excursion - (delphi-progress-start) + (opascal-token-start (opascal-previous-token (opascal-current-token))))) + +(defun opascal-debug-show-current-string (from to) + (interactive "r") + (opascal-debug-log "String: %S" (buffer-substring from to))) + +(defun opascal-debug-show-is-stable () + (interactive) + (opascal-debug-log "stable: %S prev: %S next: %S" + (opascal-is-stable-literal (point)) + (opascal-literal-kind (1- (point))) + (opascal-literal-kind (point)))) + +(defun opascal-debug-unparse-buffer () + (interactive) + (opascal-set-text-properties (point-min) (point-max) nil)) + +(defun opascal-debug-parse-region (from to) + (interactive "r") + (let ((opascal-verbose t)) + (opascal-save-excursion + (opascal-progress-start) + (opascal-parse-region from to) + (opascal-progress-done "Parsing done")))) + +(defun opascal-debug-parse-window () + (interactive) + (opascal-debug-parse-region (window-start) (window-end))) + +(defun opascal-debug-parse-buffer () + (interactive) + (opascal-debug-parse-region (point-min) (point-max))) + +(defun opascal-debug-fontify-window () + (interactive) + (opascal-fontify-region (window-start) (window-end) t)) + +(defun opascal-debug-fontify-buffer () + (interactive) + (opascal-fontify-region (point-min) (point-max) t)) + +(defun opascal-debug-tokenize-region (from to) + (interactive) + (opascal-save-excursion + (opascal-progress-start) (goto-char from) (while (< (point) to) - (goto-char (delphi-token-end (delphi-current-token))) - (delphi-step-progress (point) "Tokenizing" delphi-scanning-progress-step)) - (delphi-progress-done "Tokenizing done"))) - -(defun delphi-debug-tokenize-buffer () - (interactive) - (delphi-debug-tokenize-region (point-min) (point-max))) - -(defun delphi-debug-tokenize-window () - (interactive) - (delphi-debug-tokenize-region (window-start) (window-end))) - -(defun delphi-newline () - "Terminate the current line with a newline and indent the next, unless -`delphi-newline-always-indents' is nil, in which case no reindenting occurs." - (interactive) - ;; Remove trailing spaces - (delete-horizontal-space) - (newline) - (when delphi-newline-always-indents - ;; Indent both the (now) previous and current line first. - (save-excursion - (forward-line -1) - (delphi-indent-line)) - (delphi-indent-line))) - - -(defun delphi-tab () + (goto-char (opascal-token-end (opascal-current-token))) + (opascal-step-progress (point) "Tokenizing" opascal-scanning-progress-step)) + (opascal-progress-done "Tokenizing done"))) + +(defun opascal-debug-tokenize-buffer () + (interactive) + (opascal-debug-tokenize-region (point-min) (point-max))) + +(defun opascal-debug-tokenize-window () + (interactive) + (opascal-debug-tokenize-region (window-start) (window-end))) + + +(defun opascal-tab () "Indent the region, when Transient Mark mode is enabled and the region is active. Otherwise, indent the current line or insert a TAB, depending on the -value of `delphi-tab-always-indents' and the current line position." +value of `opascal-tab-always-indents' and the current line position." (interactive) (cond ((use-region-p) ;; If Transient Mark mode is enabled and the region is active, indent ;; the entire region. (indent-region (region-beginning) (region-end))) - ((or delphi-tab-always-indents - (save-excursion (skip-chars-backward delphi-space-chars) (bolp))) + ((or opascal-tab-always-indents + (save-excursion (skip-chars-backward opascal-space-chars) (bolp))) ;; Otherwise, if we are configured always to indent (regardless of the ;; point's position in the line) or we are before the first non-space ;; character on the line, indent the line. - (delphi-indent-line)) + (opascal-indent-line)) (t ;; Otherwise, insert a tab character. (insert "\t")))) -(defun delphi-is-directory (path) +(defun opascal-is-directory (path) ;; True if the specified path is an existing directory. (let ((attributes (file-attributes path))) (and attributes (car attributes)))) -(defun delphi-is-file (path) +(defun opascal-is-file (path) ;; True if the specified file exists as a file. (let ((attributes (file-attributes path))) (and attributes (null (car attributes))))) -(defun delphi-search-directory (unit dir &optional recurse) +(defun opascal-search-directory (unit dir &optional recurse) ;; Searches for the unit in the specified directory. If recurse is true, then ;; the directory is recursively searched. File name comparison is done in a ;; case insensitive manner. - (when (delphi-is-directory dir) + (when (opascal-is-directory dir) (let ((files (directory-files dir)) (unit-file (downcase unit))) (catch 'done ;; Search for the file. - (mapc #'(lambda (file) - (let ((path (concat dir "/" file))) - (if (and (string= unit-file (downcase file)) - (delphi-is-file path)) - (throw 'done path)))) - files) + (dolist (file files) + (let ((path (concat dir "/" file))) + (if (and (string= unit-file (downcase file)) + (opascal-is-file path)) + (throw 'done path)))) ;; Not found. Search subdirectories. (when recurse - (mapc #'(lambda (subdir) - (unless (member subdir '("." "..")) - (let ((path (delphi-search-directory - unit (concat dir "/" subdir) recurse))) - (if path (throw 'done path))))) - files)) + (dolist (subdir files) + (unless (member subdir '("." "..")) + (let ((path (opascal-search-directory + unit (concat dir "/" subdir) recurse))) + (if path (throw 'done path)))))) ;; Not found. nil)))) -(defun delphi-find-unit-in-directory (unit dir) +(defun opascal-find-unit-in-directory (unit dir) ;; Searches for the unit in the specified directory. If the directory ends ;; in \"...\", then it is recursively searched. (let ((dir-name dir) @@ -1744,90 +1684,88 @@ ;; Ensure the trailing slash is removed. (if (string-match "^\\(.+\\)[\\\\/]$" dir-name) (setq dir-name (match-string 1 dir-name))) - (delphi-search-directory unit dir-name recurse))) + (opascal-search-directory unit dir-name recurse))) -(defun delphi-find-unit-file (unit) - ;; Finds the specified delphi source file according to `delphi-search-path'. +(defun opascal-find-unit-file (unit) + ;; Finds the specified opascal source file according to `opascal-search-path'. ;; If found, the full path is returned, otherwise nil is returned. (catch 'done - (cond ((null delphi-search-path) - (delphi-find-unit-in-directory unit ".")) - - ((stringp delphi-search-path) - (delphi-find-unit-in-directory unit delphi-search-path)) - - ((mapc - #'(lambda (dir) - (let ((file (delphi-find-unit-in-directory unit dir))) - (if file (throw 'done file)))) - delphi-search-path))) + (cond ((null opascal-search-path) + (opascal-find-unit-in-directory unit ".")) + + ((stringp opascal-search-path) + (opascal-find-unit-in-directory unit opascal-search-path)) + + ((dolist (dir opascal-search-path) + (let ((file (opascal-find-unit-in-directory unit dir))) + (if file (throw 'done file)))))) nil)) -(defun delphi-find-unit (unit) - "Find the specified Delphi source file according to `delphi-search-path'. +(defun opascal-find-unit (unit) + "Find the specified OPascal source file according to `opascal-search-path'. If no extension is specified, .pas is assumed. Creates a buffer for the unit." - (interactive "sDelphi unit name: ") + (interactive "sOPascal unit name: ") (let* ((unit-file (if (string-match "^\\(.*\\)\\.[a-z]+$" unit) unit (concat unit ".pas"))) - (file (delphi-find-unit-file unit-file))) + (file (opascal-find-unit-file unit-file))) (if (null file) (error "unit not found: %s" unit-file) (find-file file) - (if (not (derived-mode-p 'delphi-mode)) - (delphi-mode))) + (if (not (derived-mode-p 'opascal-mode)) + (opascal-mode))) file)) -(defun delphi-find-current-def () +(defun opascal-find-current-def () "Find the definition of the identifier under the current point." (interactive) - (error "delphi-find-current-def: not implemented yet")) + (error "opascal-find-current-def: not implemented yet")) -(defun delphi-find-current-xdef () +(defun opascal-find-current-xdef () "Find the definition of the identifier under the current point, searching in external units if necessary (as listed in the current unit's use clause). The set of directories to search for a unit is specified by the global variable -`delphi-search-path'." +`opascal-search-path'." (interactive) - (error "delphi-find-current-xdef: not implemented yet")) + (error "opascal-find-current-xdef: not implemented yet")) -(defun delphi-find-current-body () +(defun opascal-find-current-body () "Find the body of the identifier under the current point, assuming it is a routine." (interactive) - (error "delphi-find-current-body: not implemented yet")) + (error "opascal-find-current-body: not implemented yet")) -(defun delphi-fill-comment () +(defun opascal-fill-comment () "Fill the text of the current comment, according to `fill-column'. An error is raised if not in a comment." (interactive) (save-excursion (save-restriction - (let* ((comment (delphi-current-token)) - (comment-kind (delphi-token-kind comment))) - (if (not (delphi-is comment-kind delphi-comments)) + (let* ((comment (opascal-current-token)) + (comment-kind (opascal-token-kind comment))) + (if (not (opascal-is comment-kind opascal-comments)) (error "Not in a comment") - (let* ((start-comment (delphi-comment-block-start comment)) - (end-comment (delphi-comment-block-end comment)) - (comment-start (delphi-token-start start-comment)) - (comment-end (delphi-token-end end-comment)) - (content-start (delphi-comment-content-start start-comment)) - (content-indent (delphi-column-of content-start)) + (let* ((start-comment (opascal-comment-block-start comment)) + (end-comment (opascal-comment-block-end comment)) + (comment-start (opascal-token-start start-comment)) + (comment-end (opascal-token-end end-comment)) + (content-start (opascal-comment-content-start start-comment)) + (content-indent (opascal-column-of content-start)) (content-prefix (make-string content-indent ?\s)) - (content-prefix-re delphi-leading-spaces-re) + (content-prefix-re opascal-leading-spaces-re) (p nil) (marked-point (point-marker))) ; Maintain our position reliably. (when (eq 'comment-single-line comment-kind) ;; // style comments need more work. (setq content-prefix - (let ((comment-indent (delphi-column-of comment-start))) + (let ((comment-indent (opascal-column-of comment-start))) (concat (make-string comment-indent ?\s) "//" (make-string (- content-indent comment-indent 2) ?\s))) - content-prefix-re (concat delphi-leading-spaces-re + content-prefix-re (concat opascal-leading-spaces-re "//" - delphi-spaces-re) - comment-end (if (delphi-is-literal-end comment-end) + opascal-spaces-re) + comment-end (if (opascal-is-literal-end comment-end) ;; Don't include the trailing newline. (1- comment-end) comment-end))) @@ -1879,155 +1817,144 @@ (set-marker marked-point nil) ;; React to the entire fill change as a whole. - (delphi-progress-start) - (delphi-parse-region comment-start comment-end) - (delphi-progress-done))))))) + (opascal-progress-start) + (opascal-parse-region comment-start comment-end) + (opascal-progress-done))))))) -(defun delphi-new-comment-line () +(defun opascal-new-comment-line () "If in a // comment, do a newline, indented such that one is still in the comment block. If not in a // comment, just does a normal newline." (interactive) - (let ((comment (delphi-current-token))) - (if (not (eq 'comment-single-line (delphi-token-kind comment))) + (let ((comment (opascal-current-token))) + (if (not (eq 'comment-single-line (opascal-token-kind comment))) ;; Not in a // comment. Just do the normal newline. - (delphi-newline) - (let* ((start-comment (delphi-comment-block-start comment)) - (comment-start (delphi-token-start start-comment)) - (content-start (delphi-comment-content-start start-comment)) + (newline) + (let* ((start-comment (opascal-comment-block-start comment)) + (comment-start (opascal-token-start start-comment)) + (content-start (opascal-comment-content-start start-comment)) (prefix - (concat (make-string (delphi-column-of comment-start) ?\s) "//" + (concat (make-string (opascal-column-of comment-start) ?\s) "//" (make-string (- content-start comment-start 2) ?\s)))) (delete-horizontal-space) - (newline) - (insert prefix))))) + (insert "\n" prefix))))) -(defun delphi-match-token (token limit) +(defun opascal-match-token (token limit) ;; Sets the match region used by (match-string 0) and friends to the token's ;; region. Sets the current point to the end of the token (or limit). (set-match-data nil) (if token - (let ((end (min (delphi-token-end token) limit))) - (set-match-data (list (delphi-token-start token) end)) + (let ((end (min (opascal-token-end token) limit))) + (set-match-data (list (opascal-token-start token) end)) (goto-char end) token))) -(defconst delphi-font-lock-defaults +(defconst opascal-font-lock-defaults '(nil ; We have our own fontify routine, so keywords don't apply. t ; Syntactic fontification doesn't apply. nil ; Don't care about case since we don't use regexps to find tokens. nil ; Syntax alists don't apply. nil ; Syntax begin movement doesn't apply - (font-lock-fontify-region-function . delphi-fontify-region) - (font-lock-verbose . delphi-fontifying-progress-step)) - "Delphi mode font-lock defaults. Syntactic fontification is ignored.") - -(defvar delphi-debug-mode-map - (let ((kmap (make-sparse-keymap))) - (mapc #'(lambda (binding) (define-key kmap (car binding) (cadr binding))) - '(("n" delphi-debug-goto-next-token) - ("p" delphi-debug-goto-previous-token) - ("t" delphi-debug-show-current-token) - ("T" delphi-debug-tokenize-buffer) - ("W" delphi-debug-tokenize-window) - ("g" delphi-debug-goto-point) - ("s" delphi-debug-show-current-string) - ("a" delphi-debug-parse-buffer) - ("w" delphi-debug-parse-window) - ("f" delphi-debug-fontify-window) - ("F" delphi-debug-fontify-buffer) - ("r" delphi-debug-parse-region) - ("c" delphi-debug-unparse-buffer) - ("x" delphi-debug-show-is-stable) - )) - kmap) - "Keystrokes for Delphi mode debug commands.") - -(defvar delphi-mode-map - (let ((kmap (make-sparse-keymap))) - (mapc #'(lambda (binding) (define-key kmap (car binding) (cadr binding))) - (list '("\r" delphi-newline) - '("\t" delphi-tab) - '("\177" backward-delete-char-untabify) -;; '("\C-cd" delphi-find-current-def) -;; '("\C-cx" delphi-find-current-xdef) -;; '("\C-cb" delphi-find-current-body) - '("\C-cu" delphi-find-unit) - '("\M-q" delphi-fill-comment) - '("\M-j" delphi-new-comment-line) - ;; Debug bindings: - (list "\C-c\C-d" delphi-debug-mode-map))) - kmap) - "Keymap used in Delphi mode.") - -;;;###autoload -(define-derived-mode delphi-mode prog-mode "Delphi" - "Major mode for editing Delphi code. \\ -\\[delphi-tab]\t- Indents the current line (or region, if Transient Mark mode -\t is enabled and the region is active) of Delphi code. -\\[delphi-find-unit]\t- Search for a Delphi source file. -\\[delphi-fill-comment]\t- Fill the current comment. -\\[delphi-new-comment-line]\t- If in a // comment, do a new comment line. + (font-lock-fontify-region-function . opascal-fontify-region) + (font-lock-verbose . opascal-fontifying-progress-step)) + "OPascal mode font-lock defaults. Syntactic fontification is ignored.") + +(defvar opascal-debug-mode-map + (let ((kmap (make-sparse-keymap))) + (dolist (binding '(("n" opascal-debug-goto-next-token) + ("p" opascal-debug-goto-previous-token) + ("t" opascal-debug-show-current-token) + ("T" opascal-debug-tokenize-buffer) + ("W" opascal-debug-tokenize-window) + ("g" opascal-debug-goto-point) + ("s" opascal-debug-show-current-string) + ("a" opascal-debug-parse-buffer) + ("w" opascal-debug-parse-window) + ("f" opascal-debug-fontify-window) + ("F" opascal-debug-fontify-buffer) + ("r" opascal-debug-parse-region) + ("c" opascal-debug-unparse-buffer) + ("x" opascal-debug-show-is-stable))) + (define-key kmap (car binding) (cadr binding))) + kmap) + "Keystrokes for OPascal mode debug commands.") + +(defvar opascal-mode-map + (let ((kmap (make-sparse-keymap))) + (dolist (binding + (list ;; '("\C-cd" opascal-find-current-def) + ;; '("\C-cx" opascal-find-current-xdef) + ;; '("\C-cb" opascal-find-current-body) + '("\C-cu" opascal-find-unit) + '("\M-q" opascal-fill-comment) + '("\M-j" opascal-new-comment-line) + ;; Debug bindings: + (list "\C-c\C-d" opascal-debug-mode-map))) + (define-key kmap (car binding) (cadr binding))) + kmap) + "Keymap used in OPascal mode.") + +(define-obsolete-variable-alias 'delphi-mode-hook 'opascal-mode-hook "24.4") +;;;###autoload +(define-obsolete-function-alias 'delphi-mode 'opascal-mode "24.4") +;;;###autoload +(define-derived-mode opascal-mode prog-mode "OPascal" + "Major mode for editing OPascal code. \\ +\\[opascal-find-unit]\t- Search for a OPascal source file. +\\[opascal-fill-comment]\t- Fill the current comment. +\\[opascal-new-comment-line]\t- If in a // comment, do a new comment line. \\[indent-region] also works for indenting a whole region. Customization: - `delphi-indent-level' (default 3) - Indentation of Delphi statements with respect to containing block. - `delphi-compound-block-indent' (default 0) + `opascal-indent-level' (default 3) + Indentation of OPascal statements with respect to containing block. + `opascal-compound-block-indent' (default 0) Extra indentation for blocks in compound statements. - `delphi-case-label-indent' (default 0) + `opascal-case-label-indent' (default 0) Extra indentation for case statement labels. - `delphi-tab-always-indents' (default t) - Non-nil means TAB in Delphi mode should always reindent the current line, + `opascal-tab-always-indents' (default `tab-always-indents') + Non-nil means TAB in OPascal mode should always reindent the current line, regardless of where in the line point is when the TAB command is used. - `delphi-newline-always-indents' (default t) - Non-nil means NEWLINE in Delphi mode should always reindent the current - line, insert a blank line and move to the default indent column of the - blank line. - `delphi-search-path' (default .) + `opascal-search-path' (default .) Directories to search when finding external units. - `delphi-verbose' (default nil) - If true then Delphi token processing progress is reported to the user. + `opascal-verbose' (default nil) + If true then OPascal token processing progress is reported to the user. Coloring: - `delphi-comment-face' (default font-lock-comment-face) - Face used to color Delphi comments. - `delphi-string-face' (default font-lock-string-face) - Face used to color Delphi strings. - `delphi-keyword-face' (default font-lock-keyword-face) - Face used to color Delphi keywords. - `delphi-other-face' (default nil) + `opascal-comment-face' (default font-lock-comment-face) + Face used to color OPascal comments. + `opascal-string-face' (default font-lock-string-face) + Face used to color OPascal strings. + `opascal-keyword-face' (default font-lock-keyword-face) + Face used to color OPascal keywords. + `opascal-other-face' (default nil) Face used to color everything else. -Turning on Delphi mode calls the value of the variable `delphi-mode-hook' +Turning on OPascal mode calls the value of the variable `opascal-mode-hook' with no args, if that value is non-nil." ;; Buffer locals: - (mapc #'(lambda (var) - (let ((var-symb (car var)) - (var-val (cadr var))) - (set (make-local-variable var-symb) var-val))) - (list '(indent-line-function delphi-indent-line) - '(comment-indent-function delphi-indent-line) - '(case-fold-search t) - '(delphi-progress-last-reported-point nil) - '(delphi-ignore-changes nil) - (list 'font-lock-defaults delphi-font-lock-defaults))) + (setq-local indent-line-function #'opascal-indent-line) + (setq-local comment-indent-function #'opascal-indent-line) + (setq-local case-fold-search t) + (setq-local opascal-progress-last-reported-point nil) + (setq-local opascal--ignore-changes nil) + (setq-local font-lock-defaults opascal-font-lock-defaults) + (setq-local tab-always-indent opascal-tab-always-indents) + ;; FIXME: Use syntax-propertize-function to tokenize, maybe? + ;; We need to keep track of changes to the buffer to determine if we need ;; to retokenize changed text. - (add-hook 'after-change-functions 'delphi-after-change nil t) - - (widen) - - (delphi-save-excursion - (let ((delphi-verbose t)) - (delphi-progress-start) - (delphi-parse-region (point-min) (point-max)) - (delphi-progress-done))) - - (run-mode-hooks 'delphi-mode-hook)) - -;;; delphi.el ends here + (add-hook 'after-change-functions #'opascal-after-change nil t) + + (opascal-save-excursion + (let ((opascal-verbose t)) + (opascal-progress-start) + (opascal-parse-region (point-min) (point-max)) + (opascal-progress-done)))) + +(provide 'opascal) +;;; opascal.el ends here === modified file 'test/indent/pascal.pas' --- test/indent/pascal.pas 2013-01-01 09:11:05 +0000 +++ test/indent/pascal.pas 2013-01-31 01:58:24 +0000 @@ -25,6 +25,8 @@ {$gnu-pascal,I+} +// Free-pascal style comment. + program CRTDemo; uses GPC, CRT; ------------------------------------------------------------ revno: 111635 fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13585 committer: Stefan Monnier branch nick: trunk timestamp: Wed 2013-01-30 19:58:24 -0500 message: * lisp/progmodes/pascal.el (pascal-mode-syntax-table): Accept //..\n comments. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 23:50:11 +0000 +++ lisp/ChangeLog 2013-01-31 00:58:24 +0000 @@ -1,3 +1,8 @@ +2013-01-31 Stefan Monnier + + * progmodes/pascal.el (pascal-mode-syntax-table): Accept //..\n comments + (bug#13585). + 2013-01-30 Juri Linkov * frame.el (toggle-frame-maximized, toggle-frame-fullscreen): === modified file 'lisp/progmodes/pascal.el' --- lisp/progmodes/pascal.el 2013-01-01 09:11:05 +0000 +++ lisp/progmodes/pascal.el 2013-01-31 00:58:24 +0000 @@ -138,6 +138,9 @@ ;; find about the syntax of Pascal's comments said that (* ... } is ;; a valid comment, just as { ... *) or (* ... *) or { ... }. (modify-syntax-entry ?* ". 23" st) + ;; Allow //...\n comments as accepted by Free Pascal (bug#13585). + (modify-syntax-entry ?/ ". 12c" st) + (modify-syntax-entry ?\n "> c" st) (modify-syntax-entry ?{ "<" st) (modify-syntax-entry ?} ">" st) (modify-syntax-entry ?+ "." st) ------------------------------------------------------------ revno: 111634 committer: Juri Linkov branch nick: trunk timestamp: Thu 2013-01-31 01:50:11 +0200 message: * lisp/frame.el (toggle-frame-maximized, toggle-frame-fullscreen): Use fullboth as an alias for fullscreen. Suggested by Jan Djärv in . diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 20:46:10 +0000 +++ lisp/ChangeLog 2013-01-30 23:50:11 +0000 @@ -1,3 +1,9 @@ +2013-01-30 Juri Linkov + + * frame.el (toggle-frame-maximized, toggle-frame-fullscreen): + Use fullboth as an alias for fullscreen. Suggested by Jan Djärv in + . + 2013-01-30 Stefan Monnier * progmodes/make-mode.el (makefile-backslash-region): Don't compute === modified file 'lisp/frame.el' --- lisp/frame.el 2013-01-21 10:45:20 +0000 +++ lisp/frame.el 2013-01-30 23:50:11 +0000 @@ -1666,7 +1666,7 @@ after disabling fullscreen mode. See also `toggle-frame-fullscreen'." (interactive) - (if (eq (frame-parameter nil 'fullscreen) 'fullscreen) + (if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth)) (modify-frame-parameters nil `((maximized @@ -1690,10 +1690,10 @@ (modify-frame-parameters nil `((maximized - . ,(unless (eq (frame-parameter nil 'fullscreen) 'fullscreen) + . ,(unless (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth)) (frame-parameter nil 'fullscreen))) (fullscreen - . ,(if (eq (frame-parameter nil 'fullscreen) 'fullscreen) + . ,(if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth)) (if (eq (frame-parameter nil 'maximized) 'maximized) 'maximized) 'fullscreen))))) ------------------------------------------------------------ revno: 111633 author: Christopher Schmidt committer: Katsumi Yamaoka branch nick: trunk timestamp: Wed 2013-01-30 22:45:32 +0000 message: lisp/gnus/gnus-int.el (gnus-backend-trace): Honour gnus-backend-trace diff: === modified file 'lisp/gnus/ChangeLog' --- lisp/gnus/ChangeLog 2013-01-30 10:43:40 +0000 +++ lisp/gnus/ChangeLog 2013-01-30 22:45:32 +0000 @@ -1,5 +1,8 @@ 2013-01-30 Christopher Schmidt + * gnus-int.el (gnus-backend-trace-elapsed): New variable. + (gnus-backend-trace): Honour gnus-backend-trace. + * mml.el (mml-insert-part): Insert closing tag. * mm-decode.el (mm-save-part): Handle invalid read-file-name results. === modified file 'lisp/gnus/gnus-int.el' --- lisp/gnus/gnus-int.el 2013-01-02 16:13:04 +0000 +++ lisp/gnus/gnus-int.el 2013-01-30 22:45:32 +0000 @@ -248,18 +248,20 @@ 'denied)) (defvar gnus-backend-trace nil) +(defvar gnus-backend-trace-elapsed nil) (defun gnus-backend-trace (type form) - (with-current-buffer (get-buffer-create "*gnus trace*") - (buffer-disable-undo) - (goto-char (point-max)) - (insert (format-time-string "%H:%M:%S") - (format " %.2fs %s %S\n" - (if (numberp gnus-backend-trace) - (- (float-time) gnus-backend-trace) - 0) - type form)) - (setq gnus-backend-trace (float-time)))) + (when gnus-backend-trace + (with-current-buffer (get-buffer-create "*gnus trace*") + (buffer-disable-undo) + (goto-char (point-max)) + (insert (format-time-string "%H:%M:%S") + (format " %.2fs %s %S\n" + (if (numberp gnus-backend-trace-elapsed) + (- (float-time) gnus-backend-trace-elapsed) + 0) + type form)) + (setq gnus-backend-trace-elapsed (float-time))))) (defun gnus-open-server (gnus-command-method) "Open a connection to GNUS-COMMAND-METHOD." ------------------------------------------------------------ revno: 111632 committer: Stefan Monnier branch nick: trunk timestamp: Wed 2013-01-30 15:46:10 -0500 message: * lisp/progmodes/make-mode.el (makefile-backslash-region): Don't compute column if we're just deleting the backslashes. (makefile-fill-paragraph): Use eolp. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 19:20:46 +0000 +++ lisp/ChangeLog 2013-01-30 20:46:10 +0000 @@ -1,3 +1,9 @@ +2013-01-30 Stefan Monnier + + * progmodes/make-mode.el (makefile-backslash-region): Don't compute + column if we're just deleting the backslashes. + (makefile-fill-paragraph): Use eolp. + 2013-01-30 Michael Albinus * autorevert.el (auto-revert-use-notify): Fix docstring. === modified file 'lisp/progmodes/make-mode.el' --- lisp/progmodes/make-mode.el 2013-01-03 08:23:10 +0000 +++ lisp/progmodes/make-mode.el 2013-01-30 20:46:10 +0000 @@ -1213,26 +1213,23 @@ (save-excursion (goto-char from) (let ((column makefile-backslash-column) - (endmark (make-marker))) - (move-marker endmark to) + (endmark (copy-marker to))) ;; Compute the smallest column number past the ends of all the lines. - (if makefile-backslash-align - (progn - (if (not delete-flag) - (while (< (point) to) - (end-of-line) - (if (= (preceding-char) ?\\) - (progn (forward-char -1) - (skip-chars-backward " \t"))) - (setq column (max column (1+ (current-column)))) - (forward-line 1))) - ;; Adjust upward to a tab column, if that doesn't push - ;; past the margin. - (if (> (% column tab-width) 0) - (let ((adjusted (* (/ (+ column tab-width -1) tab-width) - tab-width))) - (if (< adjusted (window-width)) - (setq column adjusted)))))) + (when (and makefile-backslash-align (not delete-flag)) + (while (< (point) to) + (end-of-line) + (if (= (preceding-char) ?\\) + (progn (forward-char -1) + (skip-chars-backward " \t"))) + (setq column (max column (1+ (current-column)))) + (forward-line 1)) + ;; Adjust upward to a tab column, if that doesn't push + ;; past the margin. + (if (> (% column tab-width) 0) + (let ((adjusted (* (/ (+ column tab-width -1) tab-width) + tab-width))) + (if (< adjusted (window-width)) + (setq column adjusted))))) ;; Don't modify blank lines at start of region. (goto-char from) (while (and (< (point) endmark) (eolp)) @@ -1296,9 +1293,9 @@ (while (= (preceding-char) ?\\) (end-of-line 0)) ;; Maybe we hit bobp, in which case we are not at EOL. - (if (eq (point) (line-end-position)) - (forward-char)) - (point))) + (if (eolp) + (1+ (point)) + (point)))) (end (save-excursion (while (= (preceding-char) ?\\) ------------------------------------------------------------ revno: 111631 committer: Michael Albinus branch nick: trunk timestamp: Wed 2013-01-30 20:20:46 +0100 message: * autorevert.el (auto-revert-use-notify): Fix docstring. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 17:57:54 +0000 +++ lisp/ChangeLog 2013-01-30 19:20:46 +0000 @@ -1,3 +1,7 @@ +2013-01-30 Michael Albinus + + * autorevert.el (auto-revert-use-notify): Fix docstring. + 2013-01-30 Leo Liu * imenu.el (imenu--truncate-items): Fix subalist checking. === modified file 'lisp/autorevert.el' --- lisp/autorevert.el 2013-01-29 16:03:40 +0000 +++ lisp/autorevert.el 2013-01-30 19:20:46 +0000 @@ -278,7 +278,7 @@ "If non-nil Auto Revert Mode uses file notification functions. This requires Emacs being compiled with file notification support (see `auto-revert-notify-enabled'). You should set this -variable through Custom only." +variable through Custom." :group 'auto-revert :type 'boolean :set (lambda (variable value) ------------------------------------------------------------ revno: 111630 fixes bug: http://debbugs.gnu.org/13576 committer: Leo Liu branch nick: trunk timestamp: Thu 2013-01-31 01:57:54 +0800 message: * lisp/imenu.el (imenu--truncate-items): Fix subalist checking. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 17:16:30 +0000 +++ lisp/ChangeLog 2013-01-30 17:57:54 +0000 @@ -1,3 +1,8 @@ +2013-01-30 Leo Liu + + * imenu.el (imenu--truncate-items): Fix subalist checking. + (Bug#13576) + 2013-01-30 Glenn Morris * mouse.el (mouse-drag-line): Avoid pushing same event onto === modified file 'lisp/imenu.el' --- lisp/imenu.el 2013-01-30 08:07:37 +0000 +++ lisp/imenu.el 2013-01-30 17:57:54 +0000 @@ -555,16 +555,14 @@ (defun imenu--truncate-items (menulist) "Truncate all strings in MENULIST to `imenu-max-item-length'." - (mapcar (lambda (item) - (cond - ((consp (cdr item)) - (imenu--truncate-items (cdr item))) - ;; truncate if necessary - ((and (numberp imenu-max-item-length) - (> (length (car item)) imenu-max-item-length)) - (setcar item (substring (car item) 0 imenu-max-item-length))))) - menulist)) - + (mapc (lambda (item) + ;; truncate if necessary + (when (and (numberp imenu-max-item-length) + (> (length (car item)) imenu-max-item-length)) + (setcar item (substring (car item) 0 imenu-max-item-length))) + (when (imenu--subalist-p item) + (imenu--truncate-items (cdr item)))) + menulist)) (defun imenu--make-index-alist (&optional noerror) "Create an index alist for the definitions in the current buffer. ------------------------------------------------------------ revno: 111629 [merge] committer: Glenn Morris branch nick: trunk timestamp: Wed 2013-01-30 09:16:30 -0800 message: Merge from emacs-24; up to r111208 diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 17:03:44 +0000 +++ lisp/ChangeLog 2013-01-30 17:16:30 +0000 @@ -1,3 +1,15 @@ +2013-01-30 Glenn Morris + + * mouse.el (mouse-drag-line): Avoid pushing same event onto + unread-command-events twice in some cases. This tries to implement + the 2012-07-26 changes in a different way. (Bug#13560) + +2013-01-30 Fabián Ezequiel Gallina + + * progmodes/python.el + (python-pdbtrack-comint-output-filter-function): Enhancements on + stacktrace detection. (thanks @gnovak) + 2013-01-30 Stefan Monnier * jit-lock.el (jit-lock-stealth-chunk-start): Don't widen (bug#13542). === modified file 'lisp/mouse.el' --- lisp/mouse.el 2013-01-01 09:11:05 +0000 +++ lisp/mouse.el 2013-01-30 17:14:24 +0000 @@ -425,7 +425,7 @@ (frame-parameters frame))) 'right))) (draggable t) - finished event position growth dragged) + event position growth dragged) (cond ((eq line 'header) ;; Check whether header-line can be dragged at all. @@ -456,39 +456,33 @@ ;; Start tracking. (track-mouse - ;; Loop reading events and sampling the position of the mouse. - (while (not finished) - (setq event (read-event)) + ;; Loop reading events and sampling the position of the mouse, + ;; until there is a non-mouse-movement event. Also, + ;; scroll-bar-movement events are the same as mouse movement for + ;; our purposes. (Why? -- cyd) + ;; If you change this, check that all of the following still work: + ;; Resizing windows by dragging mode-lines and header lines, + ;; and vertical lines (in windows without scroll bars). + ;; Doing this should not select another window, even if + ;; mouse-autoselect-window is non-nil. + ;; Mouse-1 clicks in Info header lines should advance position + ;; by one node at a time if mouse-1-click-follows-link is non-nil, + ;; otherwise they should just select the window. + (while (progn + (setq event (read-event)) + (memq (car-safe event) + '(mouse-movement scroll-bar-movement + switch-frame select-window))) (setq position (mouse-position)) ;; Do nothing if ;; - there is a switch-frame event. ;; - the mouse isn't in the frame that we started in ;; - the mouse isn't in any Emacs frame - ;; Drag if - ;; - there is a mouse-movement event - ;; - there is a scroll-bar-movement event (Why? -- cyd) - ;; (same as mouse movement for our purposes) - ;; Quit if - ;; - there is a keyboard event or some other unknown event. (cond - ((not (consp event)) - (setq finished t)) ((memq (car event) '(switch-frame select-window)) nil) - ((not (memq (car event) '(mouse-movement scroll-bar-movement))) - (when (consp event) - ;; Do not unread a drag-mouse-1 event to avoid selecting - ;; some other window. For vertical line dragging do not - ;; unread mouse-1 events either (but only if we dragged at - ;; least once to allow mouse-1 clicks get through). - (unless (and dragged - (if (eq line 'vertical) - (memq (car event) '(drag-mouse-1 mouse-1)) - (eq (car event) 'drag-mouse-1))) - (push event unread-command-events))) - (setq finished t)) - ((not (and (eq (car position) frame) - (cadr position))) + ((not (and (eq (car position) frame) + (cadr position))) nil) ((eq line 'vertical) ;; Drag vertical divider. @@ -512,12 +506,13 @@ growth (- growth))))))) ;; Process the terminating event. - (when (and (mouse-event-p event) on-link (not dragged) - (mouse--remap-link-click-p start-event event)) - ;; If mouse-2 has never been done by the user, it doesn't have - ;; the necessary property to be interpreted correctly. - (put 'mouse-2 'event-kind 'mouse-click) - (setcar event 'mouse-2) + (unless dragged + (when (and (mouse-event-p event) on-link + (mouse--remap-link-click-p start-event event)) + ;; If mouse-2 has never been done by the user, it doesn't have + ;; the necessary property to be interpreted correctly. + (put 'mouse-2 'event-kind 'mouse-click) + (setcar event 'mouse-2)) (push event unread-command-events)))) (defun mouse-drag-mode-line (start-event) === modified file 'lisp/progmodes/python.el' --- lisp/progmodes/python.el 2013-01-30 08:07:37 +0000 +++ lisp/progmodes/python.el 2013-01-30 17:16:30 +0000 @@ -2327,15 +2327,17 @@ (file-name (with-temp-buffer (insert full-output) - (goto-char (point-min)) - ;; OK, this sucked but now it became a cool hack. The - ;; stacktrace information normally is on the first line - ;; but in some cases (like when doing a step-in) it is - ;; on the second. - (when (or (looking-at python-pdbtrack-stacktrace-info-regexp) - (and - (forward-line) - (looking-at python-pdbtrack-stacktrace-info-regexp))) + ;; When the debugger encounters a pdb.set_trace() + ;; command, it prints a single stack frame. Sometimes + ;; it prints a bit of extra information about the + ;; arguments of the present function. When ipdb + ;; encounters an exception, it prints the _entire_ stack + ;; trace. To handle all of these cases, we want to find + ;; the _last_ stack frame printed in the most recent + ;; batch of output, then jump to the corrsponding + ;; file/line number. + (goto-char (point-max)) + (when (re-search-backward python-pdbtrack-stacktrace-info-regexp nil t) (setq line-number (string-to-number (match-string-no-properties 2))) (match-string-no-properties 1))))) ------------------------------------------------------------ revno: 111628 fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13542 committer: Stefan Monnier branch nick: trunk timestamp: Wed 2013-01-30 12:03:44 -0500 message: * lisp/jit-lock.el (jit-lock-stealth-chunk-start): Don't widen. (jit-lock-mode, jit-lock-functions, jit-lock-context-unfontify-pos): Use defvar-local. (jit-lock-register): Use setq-local. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 14:14:27 +0000 +++ lisp/ChangeLog 2013-01-30 17:03:44 +0000 @@ -1,3 +1,10 @@ +2013-01-30 Stefan Monnier + + * jit-lock.el (jit-lock-stealth-chunk-start): Don't widen (bug#13542). + (jit-lock-mode, jit-lock-functions, jit-lock-context-unfontify-pos): + Use defvar-local. + (jit-lock-register): Use setq-local. + 2013-01-30 Jay Belanger * calc-units.el (math-default-units-table): Remove initial value. @@ -19,8 +26,8 @@ 2013-01-30 Fabián Ezequiel Gallina - * progmodes/python.el (python-shell-parse-command): Find - python-shell-interpreter with modified environment. + * progmodes/python.el (python-shell-parse-command): + Find python-shell-interpreter with modified environment. 2013-01-30 Stefan Monnier @@ -30,7 +37,7 @@ Amend to fontify /regexp/s in actions correctly. * cc-awk.el (c-awk-harmless-char-re, c-awk-harmless-string*-re): - (c-awk-harmless-string*-here-re): braces, parens and semicolons + (c-awk-harmless-string*-here-re): Braces, parens and semicolons are no longer included. (c-awk-harmless-line-char-re, c-awk-harmless-line-string*-re): What used to be these variables without "-line" in the name. @@ -47,13 +54,13 @@ 2013-01-29 Michael Albinus - * autorevert.el (auto-revert-use-notify): Use - `custom-initialize-default' for initialization. (Bug#13583) + * autorevert.el (auto-revert-use-notify): + Use `custom-initialize-default' for initialization. (Bug#13583) * net/ange-ftp.el (ange-ftp-skip-msgs): Add another message. - * net/tramp-sh.el (tramp-sh-handle-start-file-process): Catch - `suppress'. Otherwise, `tramp-run-real-handler' might be called + * net/tramp-sh.el (tramp-sh-handle-start-file-process): + Catch `suppress'. Otherwise, `tramp-run-real-handler' might be called in `tramp-file-name-handler'. (tramp-gw-tunnel-method, tramp-gw-socks-method): Declare for compatibility. === modified file 'lisp/jit-lock.el' --- lisp/jit-lock.el 2013-01-13 01:23:48 +0000 +++ lisp/jit-lock.el 2013-01-30 17:03:44 +0000 @@ -132,20 +132,16 @@ ;;; Variables that are not customizable. -(defvar jit-lock-mode nil +(defvar-local jit-lock-mode nil "Non-nil means Just-in-time Lock mode is active.") -(make-variable-buffer-local 'jit-lock-mode) -(defvar jit-lock-functions nil +(defvar-local jit-lock-functions nil "Functions to do the actual fontification. They are called with two arguments: the START and END of the region to fontify.") -(make-variable-buffer-local 'jit-lock-functions) -(defvar jit-lock-context-unfontify-pos nil +(defvar-local jit-lock-context-unfontify-pos nil "Consider text after this position as contextually unfontified. If nil, contextual fontification is disabled.") -(make-variable-buffer-local 'jit-lock-context-unfontify-pos) - (defvar jit-lock-stealth-timer nil "Timer for stealth fontification in Just-in-time Lock mode.") @@ -305,7 +301,7 @@ If non-nil, CONTEXTUAL means that a contextual fontification would be useful." (add-hook 'jit-lock-functions fun nil t) (when (and contextual jit-lock-contextually) - (set (make-local-variable 'jit-lock-contextually) t)) + (setq-local jit-lock-contextually t)) (jit-lock-mode t)) (defun jit-lock-unregister (fun) @@ -439,41 +435,39 @@ Value is nil if there is nothing more to fontify." (if (zerop (buffer-size)) nil - (save-restriction - (widen) - (let* ((next (text-property-not-all around (point-max) 'fontified t)) - (prev (previous-single-property-change around 'fontified)) - (prop (get-text-property (max (point-min) (1- around)) - 'fontified)) - (start (cond - ((null prev) - ;; There is no property change between AROUND - ;; and the start of the buffer. If PROP is - ;; non-nil, everything in front of AROUND is - ;; fontified, otherwise nothing is fontified. - (if (eq prop t) - nil - (max (point-min) - (- around (/ jit-lock-chunk-size 2))))) - ((eq prop t) - ;; PREV is the start of a region of fontified - ;; text containing AROUND. Start fontifying a - ;; chunk size before the end of the unfontified - ;; region in front of that. - (max (or (previous-single-property-change prev 'fontified) - (point-min)) - (- prev jit-lock-chunk-size))) - (t - ;; PREV is the start of a region of unfontified - ;; text containing AROUND. Start at PREV or - ;; chunk size in front of AROUND, whichever is - ;; nearer. - (max prev (- around jit-lock-chunk-size))))) - (result (cond ((null start) next) - ((null next) start) - ((< (- around start) (- next around)) start) - (t next)))) - result)))) + (let* ((next (text-property-not-all around (point-max) 'fontified t)) + (prev (previous-single-property-change around 'fontified)) + (prop (get-text-property (max (point-min) (1- around)) + 'fontified)) + (start (cond + ((null prev) + ;; There is no property change between AROUND + ;; and the start of the buffer. If PROP is + ;; non-nil, everything in front of AROUND is + ;; fontified, otherwise nothing is fontified. + (if (eq prop t) + nil + (max (point-min) + (- around (/ jit-lock-chunk-size 2))))) + ((eq prop t) + ;; PREV is the start of a region of fontified + ;; text containing AROUND. Start fontifying a + ;; chunk size before the end of the unfontified + ;; region in front of that. + (max (or (previous-single-property-change prev 'fontified) + (point-min)) + (- prev jit-lock-chunk-size))) + (t + ;; PREV is the start of a region of unfontified + ;; text containing AROUND. Start at PREV or + ;; chunk size in front of AROUND, whichever is + ;; nearer. + (max prev (- around jit-lock-chunk-size))))) + (result (cond ((null start) next) + ((null next) start) + ((< (- around start) (- next around)) start) + (t next)))) + result))) (defun jit-lock-stealth-fontify (&optional repeat) "Fontify buffers stealthily. @@ -564,7 +558,9 @@ (when jit-lock-context-unfontify-pos ;; (message "Jit-Context %s" (buffer-name)) (save-restriction - (widen) + ;; Don't be blindsided by narrowing that starts in the middle + ;; of a jit-lock-defer-multiline. + (widen) (when (and (>= jit-lock-context-unfontify-pos (point-min)) (< jit-lock-context-unfontify-pos (point-max))) ;; If we're in text that matches a complex multi-line ------------------------------------------------------------ revno: 111627 committer: Jay Belanger branch nick: trunk timestamp: Wed 2013-01-30 08:14:27 -0600 message: calc-units.el (math-default-units-table): Remove initial value. (calc-convert-units): Treat expressions where all the units cancel as if they didn't have units. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-30 09:16:16 +0000 +++ lisp/ChangeLog 2013-01-30 14:14:27 +0000 @@ -1,3 +1,9 @@ +2013-01-30 Jay Belanger + + * calc-units.el (math-default-units-table): Remove initial value. + (calc-convert-units): Treat expressions where all the units cancel as + if they didn't have units. + 2013-01-30 Michael Albinus * net/tramp.el (tramp-process-connection-type): Fix docstring. === modified file 'lisp/calc/calc-units.el' --- lisp/calc/calc-units.el 2013-01-01 09:11:05 +0000 +++ lisp/calc/calc-units.el 2013-01-30 14:14:27 +0000 @@ -404,7 +404,7 @@ (math-composition-to-string cexpr)))))) (defvar math-default-units-table - #s(hash-table test equal data (1 (1))) + (make-hash-table :test 'equal) "A table storing previously converted units.") (defun math-get-default-units (expr) @@ -442,13 +442,19 @@ (calc-slow-wrapper (let ((expr (calc-top-n 1)) (uoldname nil) + (unitscancel nil) unew units defunits) - (unless (math-units-in-expr-p expr t) + (if (or (not (math-units-in-expr-p expr t)) + (setq unitscancel (eq (math-get-standard-units expr) 1))) (let ((uold (or old-units (progn - (setq uoldname (read-string "Old units: ")) + (setq uoldname + (if unitscancel + (read-string + "(The expression is unitless when simplified) Old Units: ") + (read-string "Old units: "))) (if (equal uoldname "") (progn (setq uoldname "1") @@ -460,47 +466,43 @@ (error "Bad format in units expression: %s" (nth 1 uold))) (setq expr (math-mul expr uold)))) (setq defunits (math-get-default-units expr)) - (if (equal defunits "1") - (progn - (calc-enter-result 1 "cvun" (math-simplify-units expr)) - (message "All units in expression cancel")) - (unless new-units - (setq new-units - (read-string (concat - (if uoldname - (concat "Old units: " - uoldname - ", new units") - "New units") - (if defunits - (concat - " (default " - defunits - "): ") - ": ")))) - (if (and - (string= new-units "") - defunits) - (setq new-units defunits))) - (when (string-match "\\` */" new-units) - (setq new-units (concat "1" new-units))) - (setq units (math-read-expr new-units)) - (when (eq (car-safe units) 'error) - (error "Bad format in units expression: %s" (nth 2 units))) - (if calc-ensure-consistent-units - (math-check-unit-consistency expr units)) - (let ((unew (math-units-in-expr-p units t)) - (std (and (eq (car-safe units) 'var) - (assq (nth 1 units) math-standard-units-systems))) - (comp (eq (car-safe units) '+))) - (unless (or unew std) - (error "No units specified")) - (let ((res - (if std - (math-simplify-units (math-to-standard-units expr (nth 1 std))) - (math-convert-units expr units (and uoldname (not (equal uoldname "1"))))))) - (math-put-default-units res (if comp units)) - (calc-enter-result 1 "cvun" res))))))) + (unless new-units + (setq new-units + (read-string (concat + (if uoldname + (concat "Old units: " + uoldname + ", new units") + "New units") + (if defunits + (concat + " (default " + defunits + "): ") + ": ")))) + (if (and + (string= new-units "") + defunits) + (setq new-units defunits))) + (when (string-match "\\` */" new-units) + (setq new-units (concat "1" new-units))) + (setq units (math-read-expr new-units)) + (when (eq (car-safe units) 'error) + (error "Bad format in units expression: %s" (nth 2 units))) + (if calc-ensure-consistent-units + (math-check-unit-consistency expr units)) + (let ((unew (math-units-in-expr-p units t)) + (std (and (eq (car-safe units) 'var) + (assq (nth 1 units) math-standard-units-systems))) + (comp (eq (car-safe units) '+))) + (unless (or unew std) + (error "No units specified")) + (let ((res + (if std + (math-simplify-units (math-to-standard-units expr (nth 1 std))) + (math-convert-units expr units (and uoldname (not (equal uoldname "1"))))))) + (math-put-default-units res (if comp units)) + (calc-enter-result 1 "cvun" res)))))) (defun calc-autorange-units (arg) (interactive "P") ------------------------------------------------------------ revno: 111626 author: Christopher Schmidt committer: Katsumi Yamaoka branch nick: trunk timestamp: Wed 2013-01-30 10:43:40 +0000 message: lisp/gnus/mml.el (mml-insert-part): Insert closing tag diff: === modified file 'lisp/gnus/ChangeLog' --- lisp/gnus/ChangeLog 2013-01-30 09:44:46 +0000 +++ lisp/gnus/ChangeLog 2013-01-30 10:43:40 +0000 @@ -1,5 +1,7 @@ 2013-01-30 Christopher Schmidt + * mml.el (mml-insert-part): Insert closing tag. + * mm-decode.el (mm-save-part): Handle invalid read-file-name results. 2013-01-21 Lars Magne Ingebrigtsen === modified file 'lisp/gnus/mml.el' --- lisp/gnus/mml.el 2013-01-01 09:11:05 +0000 +++ lisp/gnus/mml.el 2013-01-30 10:43:40 +0000 @@ -1440,7 +1440,9 @@ ;; when you send the message. (or (eq mail-user-agent 'message-user-agent) (setq mail-encode-mml t)) - (mml-insert-tag 'part 'type type 'disposition "inline")) + (mml-insert-tag 'part 'type type 'disposition "inline") + (save-excursion + (mml-insert-tag '/part))) (declare-function message-subscribed-p "message" ()) (declare-function message-make-mail-followup-to "message" ------------------------------------------------------------ revno: 111625 author: Christopher Schmidt committer: Katsumi Yamaoka branch nick: trunk timestamp: Wed 2013-01-30 09:44:46 +0000 message: lisp/gnus/mm-decode.el (mm-save-part): Handle invalid read-file-name results diff: === modified file 'lisp/gnus/ChangeLog' --- lisp/gnus/ChangeLog 2013-01-21 22:07:34 +0000 +++ lisp/gnus/ChangeLog 2013-01-30 09:44:46 +0000 @@ -1,3 +1,7 @@ +2013-01-30 Christopher Schmidt + + * mm-decode.el (mm-save-part): Handle invalid read-file-name results. + 2013-01-21 Lars Magne Ingebrigtsen * gnus-sum.el (gnus-summary-read-group-1): Protect against not being === modified file 'lisp/gnus/mm-decode.el' --- lisp/gnus/mm-decode.el 2013-01-01 09:11:05 +0000 +++ lisp/gnus/mm-decode.el 2013-01-30 09:44:46 +0000 @@ -1298,14 +1298,26 @@ (when filename (setq filename (gnus-map-function mm-file-name-rewrite-functions (file-name-nondirectory filename)))) - (setq file - (read-file-name - (or prompt - (format "Save MIME part to (default %s): " - (or filename ""))) - (or mm-default-directory default-directory) - (expand-file-name (or filename "") - (or mm-default-directory default-directory)))) + (while + (progn + (setq file + (read-file-name + (or prompt + (format "Save MIME part to (default %s): " + (or filename ""))) + (or mm-default-directory default-directory) + (expand-file-name (or filename "") + (or mm-default-directory default-directory)))) + (cond ((or (not file) (equal file "")) + (message "Please enter a file name") + t) + ((and (file-directory-p file) + (not filename)) + (message "Please enter a non-directory file name") + t) + (t nil))) + (sit-for 2) + (discard-input)) (if (file-directory-p file) (setq file (expand-file-name filename file)) (setq file (expand-file-name ------------------------------------------------------------ revno: 111624 committer: Michael Albinus + + * net/tramp.el (tramp-process-connection-type): Fix docstring. + (tramp-completion-reread-directory-timeout): Fix type. + (tramp-connection-min-time-diff): New defcustom. + + * net/tramp-sh.el (tramp-maybe-open-connection): Use it. + 2013-01-30 Glenn Morris * imenu.el (imenu-default-create-index-function): === modified file 'lisp/net/tramp-sh.el' --- lisp/net/tramp-sh.el 2013-01-30 07:37:12 +0000 +++ lisp/net/tramp-sh.el 2013-01-30 09:16:16 +0000 @@ -4357,7 +4357,7 @@ (car tramp-current-connection))) (> (tramp-time-diff (current-time) (cdr tramp-current-connection)) - 5)) + (or tramp-connection-min-time-diff 0))) (throw 'suppress 'suppress)) ;; If too much time has passed since last command was sent, look === modified file 'lisp/net/tramp.el' --- lisp/net/tramp.el 2013-01-24 09:50:02 +0000 +++ lisp/net/tramp.el 2013-01-30 09:16:16 +0000 @@ -1018,11 +1018,25 @@ ;; for an override of the system default. (defcustom tramp-process-connection-type t "Overrides `process-connection-type' for connections from Tramp. -Tramp binds process-connection-type to the value given here before +Tramp binds `process-connection-type' to the value given here before opening a connection to a remote host." :group 'tramp :type '(choice (const nil) (const t) (const pty))) +(defcustom tramp-connection-min-time-diff 5 + "Defines seconds between two consecutive connection attempts. +This is necessary as self defense mechanism, in order to avoid +yo-yo connection attempts when the remote host is unavailable. + +A value of 0 or `nil' suppresses this check. This might be +necessary, when several out-of-order copy operations are +performed, or when several asynchronous processes will be started +in a short time frame. In those cases it is recommended to +let-bind this variable." + :group 'tramp + :version "24.4" + :type '(choice (const nil) integer)) + (defcustom tramp-completion-reread-directory-timeout 10 "Defines seconds since last remote command before rereading a directory. A remote directory might have changed its contents. In order to @@ -1033,7 +1047,7 @@ would require an immediate reread during filename completion, `nil' means to use always cached values for the directory contents." :group 'tramp - :type '(choice (const nil) integer)) + :type '(choice (const nil) (const t) integer)) ;;; Internal Variables: ------------------------------------------------------------ revno: 111623 [merge] committer: Glenn Morris branch nick: trunk timestamp: Wed 2013-01-30 00:07:37 -0800 message: Merge from emacs-24; up to r111206 diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2013-01-29 20:51:07 +0000 +++ lisp/ChangeLog 2013-01-30 08:07:37 +0000 @@ -1,3 +1,17 @@ +2013-01-30 Glenn Morris + + * imenu.el (imenu-default-create-index-function): + Put back a version of the infinite loop test removed 2013-01-23. + +2013-01-30 Fabián Ezequiel Gallina + + * progmodes/python.el (python-shell-parse-command): Find + python-shell-interpreter with modified environment. + +2013-01-30 Stefan Monnier + + * emacs-lisp/cl.el (cl-set-getf): Add compatibility alias. + 2013-01-29 Alan Mackenzie Amend to fontify /regexp/s in actions correctly. @@ -21002,7 +21016,7 @@ * nxml/rng-xsd.el (rng-xsd-check-pattern): Use case-sensitive matching (Bug#8516). -2011-01-22 Jari Aalto +2011-05-22 Jari Aalto * vc/vc-dir.el (vc-default-dir-printer): Give edited tag a different face (Bug#8178). === modified file 'lisp/cedet/cedet.el' --- lisp/cedet/cedet.el 2013-01-01 09:11:05 +0000 +++ lisp/cedet/cedet.el 2013-01-28 00:34:22 +0000 @@ -4,7 +4,7 @@ ;; Author: David Ponce ;; Maintainer: Eric M. Ludlam -;; Version: 1.0pre7 +;; Version: 1.1 ;; Keywords: OO, lisp ;; This file is part of GNU Emacs. === modified file 'lisp/cedet/inversion.el' --- lisp/cedet/inversion.el 2013-01-01 09:11:05 +0000 +++ lisp/cedet/inversion.el 2013-01-28 00:34:22 +0000 @@ -3,7 +3,7 @@ ;;; Copyright (C) 2002-2003, 2005-2013 Free Software Foundation, Inc. ;; Author: Eric M. Ludlam -;; Version: 0.2 +;; Version: 1.3 ;; Keywords: OO, lisp ;; This file is part of GNU Emacs. === modified file 'lisp/cedet/semantic.el' --- lisp/cedet/semantic.el 2013-01-01 09:11:05 +0000 +++ lisp/cedet/semantic.el 2013-01-28 00:34:22 +0000 @@ -4,7 +4,7 @@ ;; Author: Eric M. Ludlam ;; Keywords: syntax tools -;; Version: 2.0 +;; Version: 2.1beta ;; This file is part of GNU Emacs. === modified file 'lisp/emacs-lisp/cl.el' --- lisp/emacs-lisp/cl.el 2013-01-02 16:13:04 +0000 +++ lisp/emacs-lisp/cl.el 2013-01-30 08:07:37 +0000 @@ -689,6 +689,7 @@ 'cl--map-keymap-recursively "24.3") (define-obsolete-function-alias 'cl-map-intervals 'cl--map-intervals "24.3") (define-obsolete-function-alias 'cl-map-extents 'cl--map-overlays "24.3") +(define-obsolete-function-alias 'cl-set-getf 'cl--set-getf "24.3") (defun cl-maclisp-member (item list) (declare (obsolete member "24.3")) === modified file 'lisp/imenu.el' --- lisp/imenu.el 2013-01-25 04:41:39 +0000 +++ lisp/imenu.el 2013-01-30 08:07:37 +0000 @@ -678,11 +678,13 @@ ;; in these major modes. But save that change for later. (cond ((and imenu-prev-index-position-function imenu-extract-index-name-function) - (let ((index-alist '()) (pos (point)) + (let ((index-alist '()) (pos -1) name) (goto-char (point-max)) ;; Search for the function (while (funcall imenu-prev-index-position-function) + (when (= pos (point)) + (error "Infinite loop at %s:%d: imenu-prev-index-position-function does not move point" (buffer-name) pos)) (setq pos (point)) (save-excursion (setq name (funcall imenu-extract-index-name-function))) === modified file 'lisp/progmodes/python.el' --- lisp/progmodes/python.el 2013-01-25 04:41:39 +0000 +++ lisp/progmodes/python.el 2013-01-30 08:07:37 +0000 @@ -1664,7 +1664,11 @@ (defun python-shell-parse-command () "Calculate the string used to execute the inferior Python process." - (format "%s %s" python-shell-interpreter python-shell-interpreter-args)) + (let ((process-environment (python-shell-calculate-process-environment)) + (exec-path (python-shell-calculate-exec-path))) + (format "%s %s" + (executable-find python-shell-interpreter) + python-shell-interpreter-args))) (defun python-shell-calculate-process-environment () "Calculate process environment given `python-shell-virtualenv-path'." === modified file 'src/ChangeLog' --- src/ChangeLog 2013-01-28 14:41:08 +0000 +++ src/ChangeLog 2013-01-30 08:07:37 +0000 @@ -1,3 +1,19 @@ +2013-01-30 Eli Zaretskii + + * w32.c (sys_open): Zero out the flags for the new file descriptor. + (sys_close): Zero out the flags for the file descriptor before + closing it. (Bug#13546) + + * w32.c (parse_root, get_volume_info, readdir, read_unc_volume) + (logon_network_drive, stat_worker, symlink, chase_symlinks): Use + CharNextExA and CharPrevExA to iterate over file names encoded in + DBCS. (Bug#13553) + + * w32.c (w32_get_long_filename, init_environment, readlink): + Support file names encoded in DBCS codepages. + (readlink): Use the current file-name-coding-system, not the ANSI + codepage, to decode and handle targets of symlinks. + 2013-01-28 Eli Zaretskii * w32.c (opendir): Now accepts a 'const char *'. === modified file 'src/w32.c' --- src/w32.c 2013-01-28 14:41:08 +0000 +++ src/w32.c 2013-01-30 08:07:37 +0000 @@ -37,7 +37,7 @@ /* must include CRT headers *before* config.h */ #include -#include /* for _mbspbrk and _mbslwr */ +#include /* for _mbspbrk, _mbslwr, _mbsrchr, ... */ #undef access #undef chdir @@ -1730,12 +1730,17 @@ else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1])) { int slashes = 2; + int dbcs_p = max_filename_mbslen () > 1; + name += 2; do { if (IS_DIRECTORY_SEP (*name) && --slashes == 0) break; - name++; + if (dbcs_p) + name = CharNextExA (file_name_codepage, name, 0); + else + name++; } while ( *name ); if (IS_DIRECTORY_SEP (name[0])) @@ -1800,7 +1805,7 @@ while (p != NULL && *p) { q = p; - p = strchr (q, '\\'); + p = _mbschr (q, '\\'); if (p) *p = '\0'; len = get_long_basename (full, o, size); if (len > 0) @@ -2072,16 +2077,16 @@ if (!GetModuleFileName (NULL, modname, MAX_PATH)) emacs_abort (); - if ((p = strrchr (modname, '\\')) == NULL) + if ((p = _mbsrchr (modname, '\\')) == NULL) emacs_abort (); *p = 0; - if ((p = strrchr (modname, '\\')) && xstrcasecmp (p, "\\bin") == 0) + if ((p = _mbsrchr (modname, '\\')) && xstrcasecmp (p, "\\bin") == 0) { char buf[SET_ENV_BUF_SIZE]; *p = 0; - for (p = modname; *p; p++) + for (p = modname; *p; p = CharNext (p)) if (*p == '\\') *p = '/'; _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname); @@ -2096,17 +2101,17 @@ || xstrcasecmp (p, "\\AMD64") == 0)) { *p = 0; - p = strrchr (modname, '\\'); + p = _mbsrchr (modname, '\\'); if (p != NULL) { *p = 0; - p = strrchr (modname, '\\'); + p = _mbsrchr (modname, '\\'); if (p && xstrcasecmp (p, "\\src") == 0) { char buf[SET_ENV_BUF_SIZE]; *p = 0; - for (p = modname; *p; p++) + for (p = modname; *p; p = CharNext (p)) if (*p == '\\') *p = '/'; _snprintf (buf, sizeof (buf)-1, "emacs_dir=%s", modname); @@ -2641,12 +2646,23 @@ { char *str = temp; int slashes = 4; + int dbcs_p = max_filename_mbslen () > 1; + rootname = temp; do { if (IS_DIRECTORY_SEP (*name) && --slashes == 0) break; - *str++ = *name++; + if (!dbcs_p) + *str++ = *name++; + else + { + const char *p = name; + + name = CharNextExA (file_name_codepage, name, 0); + memcpy (str, p, name - p); + str += name - p; + } } while ( *name ); @@ -2882,11 +2898,23 @@ { char filename[MAXNAMLEN + 3]; int ln; + int dbcs_p = max_filename_mbslen () > 1; strcpy (filename, dir_pathname); ln = strlen (filename) - 1; - if (!IS_DIRECTORY_SEP (filename[ln])) - strcat (filename, "\\"); + if (!dbcs_p) + { + if (!IS_DIRECTORY_SEP (filename[ln])) + strcat (filename, "\\"); + } + else + { + char *end = filename + ln + 1; + char *last_char = CharPrevExA (file_name_codepage, filename, end, 0); + + if (!IS_DIRECTORY_SEP (*last_char)) + strcat (filename, "\\"); + } strcat (filename, "*"); /* Note: No need to resolve symlinks in FILENAME, because @@ -2991,6 +3019,7 @@ DWORD bufsize = 512; char *buffer; char *ptr; + int dbcs_p = max_filename_mbslen () > 1; count = 1; buffer = alloca (bufsize); @@ -3001,7 +3030,13 @@ /* WNetEnumResource returns \\resource\share...skip forward to "share". */ ptr = ((LPNETRESOURCE) buffer)->lpRemoteName; ptr += 2; - while (*ptr && !IS_DIRECTORY_SEP (*ptr)) ptr++; + if (!dbcs_p) + while (*ptr && !IS_DIRECTORY_SEP (*ptr)) ptr++; + else + { + while (*ptr && !IS_DIRECTORY_SEP (*ptr)) + ptr = CharNextExA (file_name_codepage, ptr, 0); + } ptr++; strncpy (readbuf, ptr, size); @@ -3038,9 +3073,11 @@ { NETRESOURCE resource; char share[MAX_PATH]; - int i, n_slashes; + int n_slashes; char drive[4]; UINT drvtype; + char *p; + int dbcs_p; if (IS_DIRECTORY_SEP (path[0]) && IS_DIRECTORY_SEP (path[1])) drvtype = DRIVE_REMOTE; @@ -3062,13 +3099,18 @@ n_slashes = 2; strncpy (share, path, MAX_PATH); /* Truncate to just server and share name. */ - for (i = 2; i < MAX_PATH; i++) + dbcs_p = max_filename_mbslen () > 1; + for (p = share + 2; *p && p < share + MAX_PATH; ) { - if (IS_DIRECTORY_SEP (share[i]) && ++n_slashes > 3) + if (IS_DIRECTORY_SEP (*p) && ++n_slashes > 3) { - share[i] = '\0'; + *p = '\0'; break; } + if (dbcs_p) + p = CharNextExA (file_name_codepage, p, 0); + else + p++; } resource.dwType = RESOURCETYPE_DISK; @@ -3365,9 +3407,12 @@ and system files. Force all file handles to be non-inheritable. */ int res = _open (mpath, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode); - if (res >= 0) - return res; - return _open (mpath, oflag | _O_NOINHERIT, mode); + if (res < 0) + res = _open (mpath, oflag | _O_NOINHERIT, mode); + if (res >= 0 && res < MAXDESC) + fd_info[res].flags = 0; + + return res; } int @@ -3843,6 +3888,7 @@ DWORD access_rights = 0; DWORD fattrs = 0, serialnum = 0, fs_high = 0, fs_low = 0, nlinks = 1; FILETIME ctime, atime, wtime; + int dbcs_p; if (path == NULL || buf == NULL) { @@ -4040,6 +4086,7 @@ did not ask for extra precision, resolving symlinks will fly in the face of that request, since the user then wants the lightweight version of the code. */ + dbcs_p = max_filename_mbslen () > 1; rootdir = (path >= save_name + len - 1 && (IS_DIRECTORY_SEP (*path) || *path == 0)); @@ -4067,8 +4114,19 @@ } else if (rootdir) { - if (!IS_DIRECTORY_SEP (name[len-1])) - strcat (name, "\\"); + if (!dbcs_p) + { + if (!IS_DIRECTORY_SEP (name[len-1])) + strcat (name, "\\"); + } + else + { + char *end = name + len; + char *n = CharPrevExA (file_name_codepage, name, end, 0); + + if (!IS_DIRECTORY_SEP (*n)) + strcat (name, "\\"); + } if (GetDriveType (name) < 2) { errno = ENOENT; @@ -4080,15 +4138,37 @@ } else { - if (IS_DIRECTORY_SEP (name[len-1])) - name[len - 1] = 0; + if (!dbcs_p) + { + if (IS_DIRECTORY_SEP (name[len-1])) + name[len - 1] = 0; + } + else + { + char *end = name + len; + char *n = CharPrevExA (file_name_codepage, name, end, 0); + + if (IS_DIRECTORY_SEP (*n)) + *n = 0; + } /* (This is hacky, but helps when doing file completions on network drives.) Optimize by using information available from active readdir if possible. */ len = strlen (dir_pathname); - if (IS_DIRECTORY_SEP (dir_pathname[len-1])) - len--; + if (!dbcs_p) + { + if (IS_DIRECTORY_SEP (dir_pathname[len-1])) + len--; + } + else + { + char *end = dir_pathname + len; + char *n = CharPrevExA (file_name_codepage, dir_pathname, end, 0); + + if (IS_DIRECTORY_SEP (*n)) + len--; + } if (dir_find_handle != INVALID_HANDLE_VALUE && !(is_a_symlink && follow_symlinks) && strnicmp (save_name, dir_pathname, len) == 0 @@ -4359,6 +4439,7 @@ char linkfn[MAX_PATH], *tgtfn; DWORD flags = 0; int dir_access, filename_ends_in_slash; + int dbcs_p; /* Diagnostics follows Posix as much as possible. */ if (filename == NULL || linkname == NULL) @@ -4384,6 +4465,8 @@ return -1; } + dbcs_p = max_filename_mbslen () > 1; + /* Note: since empty FILENAME was already rejected, we can safely refer to FILENAME[1]. */ if (!(IS_DIRECTORY_SEP (filename[0]) || IS_DEVICE_SEP (filename[1]))) @@ -4398,8 +4481,21 @@ char tem[MAX_PATH]; char *p = linkfn + strlen (linkfn); - while (p > linkfn && !IS_ANY_SEP (p[-1])) - p--; + if (!dbcs_p) + { + while (p > linkfn && !IS_ANY_SEP (p[-1])) + p--; + } + else + { + char *p1 = CharPrevExA (file_name_codepage, linkfn, p, 0); + + while (p > linkfn && !IS_ANY_SEP (*p1)) + { + p = p1; + p1 = CharPrevExA (file_name_codepage, linkfn, p1, 0); + } + } if (p > linkfn) strncpy (tem, linkfn, p - linkfn); tem[p - linkfn] = '\0'; @@ -4414,7 +4510,15 @@ exist, but ends in a slash, we create a symlink to directory. If FILENAME exists and is a directory, we always create a symlink to directory. */ - filename_ends_in_slash = IS_DIRECTORY_SEP (filename[strlen (filename) - 1]); + if (!dbcs_p) + filename_ends_in_slash = IS_DIRECTORY_SEP (filename[strlen (filename) - 1]); + else + { + const char *end = filename + strlen (filename); + const char *n = CharPrevExA (file_name_codepage, filename, end, 0); + + filename_ends_in_slash = IS_DIRECTORY_SEP (*n); + } if (dir_access == 0 || filename_ends_in_slash) flags = SYMBOLIC_LINK_FLAG_DIRECTORY; @@ -4604,6 +4708,8 @@ WCHAR *lwname_src = reparse_data->SymbolicLinkReparseBuffer.PathBuffer + reparse_data->SymbolicLinkReparseBuffer.PrintNameOffset/sizeof(WCHAR); + /* This updates file_name_codepage which we need below. */ + int dbcs_p = max_filename_mbslen () > 1; /* According to MSDN, PrintNameLength does not include the terminating null character. */ @@ -4611,9 +4717,7 @@ memcpy (lwname, lwname_src, lwname_len); lwname[lwname_len/sizeof(WCHAR)] = 0; /* null-terminate */ - /* FIXME: Should we use the current file-name coding system - instead of the fixed value of the ANSI codepage? */ - lname_len = WideCharToMultiByte (w32_ansi_code_page, 0, lwname, -1, + lname_len = WideCharToMultiByte (file_name_codepage, 0, lwname, -1, lname, MAX_PATH, NULL, NULL); if (!lname_len) { @@ -4639,18 +4743,33 @@ else { size_t size_to_copy = buf_size; - BYTE *p = lname; + BYTE *p = lname, *p2; BYTE *pend = p + lname_len; /* Normalize like dostounix_filename does, but we don't want to assume that lname is null-terminated. */ - if (*p && p[1] == ':' && *p >= 'A' && *p <= 'Z') - *p += 'a' - 'A'; + if (dbcs_p) + p2 = CharNextExA (file_name_codepage, p, 0); + else + p2 = p + 1; + if (*p && *p2 == ':' && *p >= 'A' && *p <= 'Z') + { + *p += 'a' - 'A'; + p += 2; + } while (p <= pend) { if (*p == '\\') *p = '/'; - ++p; + if (dbcs_p) + { + p = CharNextExA (file_name_codepage, p, 0); + /* CharNextExA doesn't advance at null character. */ + if (!*p) + break; + } + else + ++p; } /* Testing for null-terminated LNAME is paranoia: WideCharToMultiByte should always return a @@ -4724,6 +4843,7 @@ char link[MAX_PATH]; ssize_t res, link_len; int loop_count = 0; + int dbcs_p; if (is_windows_9x () == TRUE || !is_symlink (file)) return (char *)file; @@ -4731,13 +4851,27 @@ if ((link_len = GetFullPathName (file, MAX_PATH, link, NULL)) == 0) return (char *)file; + dbcs_p = max_filename_mbslen () > 1; target[0] = '\0'; do { /* Remove trailing slashes, as we want to resolve the last non-trivial part of the link name. */ - while (link_len > 3 && IS_DIRECTORY_SEP (link[link_len-1])) - link[link_len--] = '\0'; + if (!dbcs_p) + { + while (link_len > 3 && IS_DIRECTORY_SEP (link[link_len-1])) + link[link_len--] = '\0'; + } + else if (link_len > 3) + { + char *n = CharPrevExA (file_name_codepage, link, link + link_len, 0); + + while (n >= link + 2 && IS_DIRECTORY_SEP (*n)) + { + n[1] = '\0'; + n = CharPrevExA (file_name_codepage, link, n, 0); + } + } res = readlink (link, target, MAX_PATH); if (res > 0) @@ -4750,8 +4884,21 @@ the symlink, then copy the result back to target. */ char *p = link + link_len; - while (p > link && !IS_ANY_SEP (p[-1])) - p--; + if (!dbcs_p) + { + while (p > link && !IS_ANY_SEP (p[-1])) + p--; + } + else + { + char *p1 = CharPrevExA (file_name_codepage, link, p, 0); + + while (p > link && !IS_ANY_SEP (*p1)) + { + p = p1; + p1 = CharPrevExA (file_name_codepage, link, p1, 0); + } + } strcpy (p, target); strcpy (target, link); } @@ -6543,15 +6690,15 @@ } } + if (fd >= 0 && fd < MAXDESC) + fd_info[fd].flags = 0; + /* Note that sockets do not need special treatment here (at least on NT and Windows 95 using the standard tcp/ip stacks) - it appears that closesocket is equivalent to CloseHandle, which is to be expected because socket handles are fully fledged kernel handles. */ rc = _close (fd); - if (rc == 0 && fd < MAXDESC) - fd_info[fd].flags = 0; - return rc; } ------------------------------------------------------------ revno: 111622 committer: Michael Albinus