diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/generic-x.el | 125 | ||||
| -rw-r--r-- | lisp/progmodes/dos.el | 183 | ||||
| -rw-r--r-- | lisp/subr.el | 2 |
4 files changed, 191 insertions, 125 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 09e0349e7f1..de2b79577e1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-08-07 Arni Magnusson <arnima@hafro.is> | ||
| 2 | |||
| 3 | * progmodes/dos.el: New file. | ||
| 4 | * generic-x.el (bat-generic-mode): Redefine as an obsolete alias to | ||
| 5 | dos-mode. | ||
| 6 | |||
| 1 | 2013-08-06 Glenn Morris <rgm@gnu.org> | 7 | 2013-08-06 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * calendar/calendar.el: Add new faces, and day-header-array. | 9 | * calendar/calendar.el: Add new faces, and day-header-array. |
diff --git a/lisp/generic-x.el b/lisp/generic-x.el index 1867759b549..698819d73a1 100644 --- a/lisp/generic-x.el +++ b/lisp/generic-x.el | |||
| @@ -460,130 +460,7 @@ like an INI file. You can add this hook to `find-file-hook'." | |||
| 460 | 460 | ||
| 461 | ;;; DOS/Windows BAT files | 461 | ;;; DOS/Windows BAT files |
| 462 | (when (memq 'bat-generic-mode generic-extras-enable-list) | 462 | (when (memq 'bat-generic-mode generic-extras-enable-list) |
| 463 | 463 | (define-obsolete-function-alias 'bat-generic-mode 'dos-mode "24.4")) | |
| 464 | (define-generic-mode bat-generic-mode | ||
| 465 | nil | ||
| 466 | nil | ||
| 467 | (eval-when-compile | ||
| 468 | (list | ||
| 469 | ;; Make this one first in the list, otherwise comments will | ||
| 470 | ;; be over-written by other variables | ||
| 471 | '("^[@ \t]*\\([rR][eE][mM][^\n\r]*\\)" 1 font-lock-comment-face t) | ||
| 472 | '("^[ \t]*\\(::.*\\)" 1 font-lock-comment-face t) | ||
| 473 | '("^[@ \t]*\\([bB][rR][eE][aA][kK]\\|[vV][eE][rR][iI][fF][yY]\\)[ \t]+\\([oO]\\([nN]\\|[fF][fF]\\)\\)" | ||
| 474 | (1 font-lock-builtin-face) | ||
| 475 | (2 font-lock-constant-face t t)) | ||
| 476 | ;; Any text (except ON/OFF) following ECHO is a string. | ||
| 477 | '("^[@ \t]*\\([eE][cC][hH][oO]\\)[ \t]+\\(\\([oO]\\([nN]\\|[fF][fF]\\)\\)\\|\\([^>|\r\n]+\\)\\)" | ||
| 478 | (1 font-lock-builtin-face) | ||
| 479 | (3 font-lock-constant-face t t) | ||
| 480 | (5 font-lock-string-face t t)) | ||
| 481 | ;; These keywords appear as the first word on a line. (Actually, they | ||
| 482 | ;; can also appear after "if ..." or "for ..." clause, but since they | ||
| 483 | ;; are frequently used in simple text, we punt.) | ||
| 484 | ;; In `generic-bat-mode-setup-function' we make the keywords | ||
| 485 | ;; case-insensitive | ||
| 486 | '("^[@ \t]*\\_<\\(for\\|if\\)\\_>" 1 font-lock-keyword-face) | ||
| 487 | ;; These keywords can be anywhere on a line | ||
| 488 | ;; In `generic-bat-mode-setup-function' we make the keywords | ||
| 489 | ;; case-insensitive | ||
| 490 | (list (regexp-opt '("do" "exist" "errorlevel" "goto" "not") 'symbols) | ||
| 491 | 1 font-lock-keyword-face) | ||
| 492 | ;; These are built-in commands. Only frequently-used ones are listed. | ||
| 493 | (list (concat "[ \t|\n]" | ||
| 494 | (regexp-opt '("CALL" "call" "Call" | ||
| 495 | "CD" "cd" "Cd" | ||
| 496 | "CLS" "cls" "Cls" | ||
| 497 | "COPY" "copy" "Copy" | ||
| 498 | "DEL" "del" "Del" | ||
| 499 | "ECHO" "echo" "Echo" | ||
| 500 | "MD" "md" "Md" | ||
| 501 | "PATH" "path" "Path" | ||
| 502 | "PAUSE" "pause" "Pause" | ||
| 503 | "PROMPT" "prompt" "Prompt" | ||
| 504 | "RD" "rd" "Rd" | ||
| 505 | "REN" "ren" "Ren" | ||
| 506 | "SET" "set" "Set" | ||
| 507 | "START" "start" "Start" | ||
| 508 | "SHIFT" "shift" "Shift") 'symbols)) | ||
| 509 | 1 font-lock-builtin-face) | ||
| 510 | '("^[ \t]*\\(:\\sw+\\)" 1 font-lock-function-name-face t) | ||
| 511 | '("\\(%\\sw+%\\)" 1 font-lock-variable-name-face t) | ||
| 512 | '("\\(%[0-9]\\)" 1 font-lock-variable-name-face t) | ||
| 513 | '("[\t ]+\\([+-/][^\t\n\" ]+\\)" 1 font-lock-type-face) | ||
| 514 | '("[ \t\n|]\\<\\([gG][oO][tT][oO]\\)\\>[ \t]*\\(\\sw+\\)?" | ||
| 515 | (1 font-lock-keyword-face) | ||
| 516 | (2 font-lock-function-name-face nil t)) | ||
| 517 | '("[ \t\n|]\\<\\([sS][eE][tT]\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*=?" | ||
| 518 | (1 font-lock-builtin-face) | ||
| 519 | (2 font-lock-variable-name-face t t)))) | ||
| 520 | '("\\.[bB][aA][tT]\\'" | ||
| 521 | "\\.[cC][mM][dD]\\'" | ||
| 522 | "\\`[cC][oO][nN][fF][iI][gG]\\." | ||
| 523 | "\\`[aA][uU][tT][oO][eE][xX][eE][cC]\\.") | ||
| 524 | '(generic-bat-mode-setup-function) | ||
| 525 | "Generic mode for MS-Windows batch files.") | ||
| 526 | |||
| 527 | (defvar bat-generic-mode-syntax-table nil | ||
| 528 | "Syntax table in use in `bat-generic-mode' buffers.") | ||
| 529 | |||
| 530 | (defvar bat-generic-mode-keymap (make-sparse-keymap) | ||
| 531 | "Keymap for `bat-generic-mode'.") | ||
| 532 | |||
| 533 | (defun bat-generic-mode-compile () | ||
| 534 | "Run the current BAT file in a compilation buffer." | ||
| 535 | (interactive) | ||
| 536 | (let ((compilation-buffer-name-function | ||
| 537 | (function | ||
| 538 | (lambda (_ign) | ||
| 539 | (concat "*" (buffer-file-name) "*"))))) | ||
| 540 | (compile | ||
| 541 | (concat (w32-shell-name) " -c " (buffer-file-name))))) | ||
| 542 | |||
| 543 | (declare-function comint-mode "comint" ()) | ||
| 544 | (declare-function comint-exec "comint" (buffer name command startfile switches)) | ||
| 545 | |||
| 546 | (defun bat-generic-mode-run-as-comint () | ||
| 547 | "Run the current BAT file in a comint buffer." | ||
| 548 | (interactive) | ||
| 549 | (require 'comint) | ||
| 550 | (let* ((file (buffer-file-name)) | ||
| 551 | (buf-name (concat "*" file "*"))) | ||
| 552 | (with-current-buffer (get-buffer-create buf-name) | ||
| 553 | (erase-buffer) | ||
| 554 | (comint-mode) | ||
| 555 | (comint-exec | ||
| 556 | buf-name | ||
| 557 | file | ||
| 558 | (w32-shell-name) | ||
| 559 | nil | ||
| 560 | (list "-c" file)) | ||
| 561 | (display-buffer buf-name)))) | ||
| 562 | |||
| 563 | (define-key bat-generic-mode-keymap "\C-c\C-c" 'bat-generic-mode-compile) | ||
| 564 | |||
| 565 | ;; Make underscores count as words | ||
| 566 | (unless bat-generic-mode-syntax-table | ||
| 567 | (setq bat-generic-mode-syntax-table (make-syntax-table)) | ||
| 568 | (modify-syntax-entry ?_ "w" bat-generic-mode-syntax-table)) | ||
| 569 | |||
| 570 | ;; bat-generic-mode doesn't use the comment functionality of | ||
| 571 | ;; define-generic-mode because it has a three-letter comment-string, | ||
| 572 | ;; so we do it here manually instead | ||
| 573 | (defun generic-bat-mode-setup-function () | ||
| 574 | (make-local-variable 'parse-sexp-ignore-comments) | ||
| 575 | (make-local-variable 'comment-start) | ||
| 576 | (make-local-variable 'comment-start-skip) | ||
| 577 | (make-local-variable 'comment-end) | ||
| 578 | (setq imenu-generic-expression '((nil "^:\\(\\sw+\\)" 1)) | ||
| 579 | parse-sexp-ignore-comments t | ||
| 580 | comment-end "" | ||
| 581 | comment-start "REM " | ||
| 582 | comment-start-skip "[Rr][Ee][Mm] *") | ||
| 583 | (set-syntax-table bat-generic-mode-syntax-table) | ||
| 584 | ;; Make keywords case-insensitive | ||
| 585 | (setq font-lock-defaults '(generic-font-lock-keywords nil t)) | ||
| 586 | (use-local-map bat-generic-mode-keymap))) | ||
| 587 | 464 | ||
| 588 | ;;; Mailagent | 465 | ;;; Mailagent |
| 589 | ;; Mailagent is a Unix mail filtering program. Anyone wanna do a | 466 | ;; Mailagent is a Unix mail filtering program. Anyone wanna do a |
diff --git a/lisp/progmodes/dos.el b/lisp/progmodes/dos.el new file mode 100644 index 00000000000..57b137f97fb --- /dev/null +++ b/lisp/progmodes/dos.el | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | ;;; dos.el --- Major mode for editing Dos scripts | ||
| 2 | |||
| 3 | ;; Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Arni Magnusson <arnima@hafro.is> | ||
| 6 | ;; Keywords: languages | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | ;; | ||
| 25 | ;; Major mode for editing Dos scripts (batch files). Provides syntax | ||
| 26 | ;; highlighting, a basic template, access to Dos help pages, imenu/outline | ||
| 27 | ;; navigation, and the ability to run scripts from within Emacs. The syntax | ||
| 28 | ;; groups for highlighting are: | ||
| 29 | ;; | ||
| 30 | ;; Face Example | ||
| 31 | ;; dos-label-face :LABEL | ||
| 32 | ;; font-lock-comment-face rem | ||
| 33 | ;; font-lock-builtin-face copy | ||
| 34 | ;; font-lock-keyword-face goto | ||
| 35 | ;; font-lock-warning-face cp | ||
| 36 | ;; font-lock-constant-face [call] prog | ||
| 37 | ;; font-lock-variable-name-face %var% | ||
| 38 | ;; font-lock-type-face -option | ||
| 39 | ;; | ||
| 40 | ;; Usage: | ||
| 41 | ;; | ||
| 42 | ;; See documentation of function `dos-mode'. | ||
| 43 | ;; | ||
| 44 | ;; Separate package `dos-indent' (Matthew Fidler) provides rudimentary | ||
| 45 | ;; indentation, see http://www.emacswiki.org/emacs/dos-indent.el. | ||
| 46 | ;; | ||
| 47 | ;; Acknowledgements: | ||
| 48 | ;; | ||
| 49 | ;; Inspired by `batch-mode' (Agnar Renolen) and `cmd-mode' (Tadamegu Furukawa). | ||
| 50 | |||
| 51 | ;;; Code: | ||
| 52 | |||
| 53 | ;; 1 Preamble | ||
| 54 | |||
| 55 | (defgroup dos nil | ||
| 56 | "Major mode for editing Dos scripts." | ||
| 57 | :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) | ||
| 58 | :group 'languages) | ||
| 59 | |||
| 60 | ;; 2 User variables | ||
| 61 | |||
| 62 | (defface dos-label-face '((t :weight bold)) | ||
| 63 | "Font Lock mode face used to highlight Dos labels." | ||
| 64 | :group 'dos) | ||
| 65 | |||
| 66 | ;; 3 Internal variables | ||
| 67 | |||
| 68 | (defvar dos-font-lock-keywords | ||
| 69 | (eval-when-compile | ||
| 70 | (let ((COMMANDS | ||
| 71 | '("assoc" "at" "attrib" "cd" "cls" "color" "copy" "date" "del" "dir" | ||
| 72 | "doskey" "echo" "endlocal" "erase" "fc" "find" "findstr" "format" | ||
| 73 | "ftype" "label" "md" "mkdir" "more" "move" "net" "path" "pause" | ||
| 74 | "popd" "prompt" "pushd" "rd" "ren" "rename" "replace" "rmdir" "set" | ||
| 75 | "setlocal" "shift" "sort" "subst" "time" "title" "tree" "type" | ||
| 76 | "ver" "vol" "xcopy")) | ||
| 77 | (CONTROLFLOW | ||
| 78 | '("call" "cmd" "defined" "do" "else" "equ" "exist" "exit" "for" "geq" | ||
| 79 | "goto" "gtr" "if" "in" "leq" "lss" "neq" "not" "start")) | ||
| 80 | (LINUX | ||
| 81 | '("cat" "cp" "ls" "mv" "rm"))) | ||
| 82 | (list | ||
| 83 | '("\\<\\(call\\|goto\\)\\>[ \t]+%?\\([A-Za-z0-9-_\\:.]+\\)%?" | ||
| 84 | (2 font-lock-constant-face t)) | ||
| 85 | '("^[ \t]*\\(@?rem\\>\\|::\\).*" | ||
| 86 | (0 font-lock-comment-face t)) | ||
| 87 | '("^:[^:].*" | ||
| 88 | . 'dos-label-face) | ||
| 89 | '("\\<\\(defined\\|set\\)\\>[ \t]*\\(\\w+\\)" | ||
| 90 | (2 font-lock-variable-name-face)) | ||
| 91 | '("%\\(\\w+\\)%?" | ||
| 92 | (1 font-lock-variable-name-face)) | ||
| 93 | '("!\\(\\w+\\)!?" ; delayed-expansion !variable! | ||
| 94 | (1 font-lock-variable-name-face)) | ||
| 95 | '("[ =][-/]+\\(\\w+\\)" | ||
| 96 | (1 font-lock-type-face append)) | ||
| 97 | (cons (regexp-opt COMMANDS 'words) font-lock-builtin-face) | ||
| 98 | (cons (regexp-opt CONTROLFLOW 'words) font-lock-keyword-face) | ||
| 99 | (cons (regexp-opt LINUX 'words) font-lock-warning-face))))) | ||
| 100 | |||
| 101 | (defvar dos-menu | ||
| 102 | '("Dos" | ||
| 103 | ["Run" dos-run :help "Run script"] | ||
| 104 | ["Run with Args" dos-run-args :help "Run script with args"] | ||
| 105 | "--" | ||
| 106 | ["Imenu" imenu :help "Navigate with imenu"] | ||
| 107 | "--" | ||
| 108 | ["Template" dos-template :help "Insert template"] | ||
| 109 | "--" | ||
| 110 | ["Help (Command)" dos-cmd-help :help "Show help page for Dos command"] | ||
| 111 | ["Help (Mode)" dos-mode-help :help "Show help page for Emacs Dos Mode"])) | ||
| 112 | |||
| 113 | (defvar dos-mode-map | ||
| 114 | (let ((map (make-sparse-keymap))) | ||
| 115 | (easy-menu-define nil map nil dos-menu) | ||
| 116 | (define-key map [?\C-c ?\C-.] 'dos-mode-help) | ||
| 117 | (define-key map [?\C-c ?\C-/] 'dos-cmd-help) | ||
| 118 | (define-key map [?\C-c ?\C-a] 'dos-run-args) | ||
| 119 | (define-key map [?\C-c ?\C-c] 'dos-run) | ||
| 120 | (define-key map [?\C-c ?\C-t] 'dos-template) | ||
| 121 | (define-key map [?\C-c ?\C-v] 'dos-run) | ||
| 122 | map)) | ||
| 123 | |||
| 124 | (defvar dos-mode-syntax-table | ||
| 125 | (let ((table (make-syntax-table))) | ||
| 126 | (modify-syntax-entry ?~ "w" table) | ||
| 127 | (modify-syntax-entry ?% "." table) | ||
| 128 | (modify-syntax-entry ?- "w" table) | ||
| 129 | (modify-syntax-entry ?_ "w" table) | ||
| 130 | (modify-syntax-entry ?{ "w" table) | ||
| 131 | (modify-syntax-entry ?} "w" table) | ||
| 132 | (modify-syntax-entry ?\\ "." table) | ||
| 133 | table)) | ||
| 134 | |||
| 135 | ;; 4 User functions | ||
| 136 | |||
| 137 | (defun dos-cmd-help (cmd) | ||
| 138 | "Show help for Dos command." | ||
| 139 | (interactive "sHelp: ") | ||
| 140 | (if (string-equal cmd "net") | ||
| 141 | (shell-command "net /?") (shell-command (concat "help " cmd)))) | ||
| 142 | |||
| 143 | (defun dos-mode-help () | ||
| 144 | "Show help page for `dos-mode'." | ||
| 145 | (interactive) | ||
| 146 | (describe-function 'dos-mode) | ||
| 147 | (switch-to-buffer "*Help*") (delete-other-windows) (message nil)) | ||
| 148 | |||
| 149 | (defun dos-run () | ||
| 150 | "Run Dos script." | ||
| 151 | (interactive) | ||
| 152 | (save-buffer) (shell-command buffer-file-name)) | ||
| 153 | |||
| 154 | (defun dos-run-args (args) | ||
| 155 | "Run Dos script with ARGS." | ||
| 156 | (interactive "sArgs: ") | ||
| 157 | (shell-command (concat buffer-file-name " " args))) | ||
| 158 | |||
| 159 | (defun dos-template () | ||
| 160 | "Insert minimal Dos template." | ||
| 161 | (interactive) | ||
| 162 | (goto-char (point-min)) (insert "@echo off\nsetlocal\n\n")) | ||
| 163 | |||
| 164 | ;; 5 Main function | ||
| 165 | |||
| 166 | ;;;###autoload | ||
| 167 | (define-derived-mode dos-mode prog-mode "Dos" | ||
| 168 | "Major mode for editing Dos scripts.\n | ||
| 169 | The `dos-mode-help' command shows this page.\n | ||
| 170 | Start a new script from `dos-template'. Read help pages for Dos commands with | ||
| 171 | `dos-cmd-help'. Navigate between sections using `imenu'. Run script using | ||
| 172 | `dos-run' and `dos-run-args'.\n | ||
| 173 | \\{dos-mode-map}" | ||
| 174 | (set (make-local-variable 'comment-start) "rem") | ||
| 175 | (set (make-local-variable 'font-lock-defaults) | ||
| 176 | '(dos-font-lock-keywords nil t)) ; case-insensitive keywords | ||
| 177 | (set (make-local-variable 'imenu-generic-expression) '((nil "^:[^:].*" 0))) | ||
| 178 | (set (make-local-variable 'outline-regexp) ":[^:]") | ||
| 179 | (set-syntax-table dos-mode-syntax-table)) | ||
| 180 | |||
| 181 | (provide 'dos) | ||
| 182 | |||
| 183 | ;;; dos.el ends here | ||
diff --git a/lisp/subr.el b/lisp/subr.el index bdeee677471..43a9fc015b1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -2755,7 +2755,7 @@ Otherwise, return nil." | |||
| 2755 | (let ((def (indirect-function object t))) | 2755 | (let ((def (indirect-function object t))) |
| 2756 | (when (consp def) | 2756 | (when (consp def) |
| 2757 | (or (eq 'macro (car def)) | 2757 | (or (eq 'macro (car def)) |
| 2758 | (and (eq 'autoload (car def)) (memq (nth 4 def) '(macro t))))))) | 2758 | (and (autoloadp def) (memq (nth 4 def) '(macro t))))))) |
| 2759 | 2759 | ||
| 2760 | (defun field-at-pos (pos) | 2760 | (defun field-at-pos (pos) |
| 2761 | "Return the field at position POS, taking stickiness etc into account." | 2761 | "Return the field at position POS, taking stickiness etc into account." |