From: Stefan Monnier Date: Wed, 7 Aug 2013 22:42:44 +0000 (-0400) Subject: * lisp/progmodes/bat-mode.el: Rename from dos.el. Use "bat-" prefix. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1686^2~378 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7679edb1e0afb258cc80657a15eebcafcbdb7f81;p=emacs.git * lisp/progmodes/bat-mode.el: Rename from dos.el. Use "bat-" prefix. (dos-mode-help): Remove. Use describe-mode (C-h m) instead. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 70e10615dd7..e1d366f0510 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2013-08-07 Stefan Monnier + * progmodes/bat-mode.el: Rename from dos.el. Use "bat-" prefix. + (dos-mode-help): Remove. Use describe-mode (C-h m) instead. + * emacs-lisp/bytecomp.el: Check existence of f in #'f. (byte-compile-callargs-warn): Use `push'. (byte-compile-arglist-warn): Ignore higher-order "calls". diff --git a/lisp/generic-x.el b/lisp/generic-x.el index 698819d73a1..c964b53952e 100644 --- a/lisp/generic-x.el +++ b/lisp/generic-x.el @@ -460,7 +460,7 @@ like an INI file. You can add this hook to `find-file-hook'." ;;; DOS/Windows BAT files (when (memq 'bat-generic-mode generic-extras-enable-list) - (define-obsolete-function-alias 'bat-generic-mode 'dos-mode "24.4")) + (define-obsolete-function-alias 'bat-generic-mode 'bat-mode "24.4")) ;;; Mailagent ;; Mailagent is a Unix mail filtering program. Anyone wanna do a diff --git a/lisp/progmodes/bat-mode.el b/lisp/progmodes/bat-mode.el new file mode 100644 index 00000000000..45c350e9847 --- /dev/null +++ b/lisp/progmodes/bat-mode.el @@ -0,0 +1,181 @@ +;;; bat-mode.el --- Major mode for editing DOS/Windows scripts + +;; Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. + +;; Author: Arni Magnusson +;; Keywords: languages + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: +;; +;; Major mode for editing DOS/Windows scripts (batch files). Provides syntax +;; highlighting, a basic template, access to DOS help pages, imenu/outline +;; navigation, and the ability to run scripts from within Emacs. The syntax +;; groups for highlighting are: +;; +;; Face Example +;; bat-label-face :LABEL +;; font-lock-comment-face rem +;; font-lock-builtin-face copy +;; font-lock-keyword-face goto +;; font-lock-warning-face cp +;; font-lock-constant-face [call] prog +;; font-lock-variable-name-face %var% +;; font-lock-type-face -option +;; +;; Usage: +;; +;; See documentation of function `bat-mode'. +;; +;; Separate package `dos-indent' (Matthew Fidler) provides rudimentary +;; indentation, see http://www.emacswiki.org/emacs/dos-indent.el. +;; +;; Acknowledgements: +;; +;; Inspired by `batch-mode' (Agnar Renolen) and `cmd-mode' (Tadamegu Furukawa). + +;;; Code: + +;; 1 Preamble + +(defgroup bat-mode nil + "Major mode for editing DOS/Windows batch files." + :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) + :group 'languages) + +;; 2 User variables + +(defface bat-label-face '((t :weight bold)) + "Font Lock mode face used to highlight labels in batch files.") + +;; 3 Internal variables + +(defvar bat-font-lock-keywords + (eval-when-compile + (let ((COMMANDS + '("assoc" "at" "attrib" "cd" "cls" "color" "copy" "date" "del" "dir" + "doskey" "echo" "endlocal" "erase" "fc" "find" "findstr" "format" + "ftype" "label" "md" "mkdir" "more" "move" "net" "path" "pause" + "popd" "prompt" "pushd" "rd" "ren" "rename" "replace" "rmdir" "set" + "setlocal" "shift" "sort" "subst" "time" "title" "tree" "type" + "ver" "vol" "xcopy")) + (CONTROLFLOW + '("call" "cmd" "defined" "do" "else" "equ" "exist" "exit" "for" "geq" + "goto" "gtr" "if" "in" "leq" "lss" "neq" "not" "start")) + (UNIX + '("bash" "cat" "cp" "fgrep" "grep" "ls" "sed" "sh" "mv" "rm"))) + `(("\\<_\\(call\\|goto\\)\\_>[ \t]+%?\\([A-Za-z0-9-_\\:.]+\\)%?" + (2 font-lock-constant-face t)) + ("^[ \t]*\\(@?rem\\_>\\|::\\).*" + (0 font-lock-comment-face t)) + ("^:[^:].*" + . 'bat-label-face) + ("\\<_\\(defined\\|set\\)\\_>[ \t]*\\(\\w+\\)" + (2 font-lock-variable-name-face)) + ("%\\(\\w+\\)%?" + (1 font-lock-variable-name-face)) + ("!\\(\\w+\\)!?" ; delayed-expansion !variable! + (1 font-lock-variable-name-face)) + ("[ =][-/]+\\(\\w+\\)" + (1 font-lock-type-face append)) + (,(concat "\\_<" (regexp-opt COMMANDS) "\\_>") . font-lock-builtin-face) + (,(concat "\\_<" (regexp-opt CONTROLFLOW) "\\_>") + . font-lock-keyword-face) + (,(concat "\\_<" (regexp-opt UNIX) "\\_>") + . font-lock-warning-face))))) + +(defvar bat-menu + '("Bat" + ["Run" bat-run :help "Run script"] + ["Run with Args" bat-run-args :help "Run script with args"] + "--" + ["Imenu" imenu :help "Navigate with imenu"] + "--" + ["Template" bat-template :help "Insert template"] + "--" + ["Help (Command)" bat-cmd-help :help "Show help page for DOS command"])) + +(defvar bat-mode-map + (let ((map (make-sparse-keymap))) + (easy-menu-define nil map nil bat-menu) + (define-key map [?\C-c ?\C-/] 'bat-cmd-help) ;FIXME: Why not C-c C-? ? + (define-key map [?\C-c ?\C-a] 'bat-run-args) + (define-key map [?\C-c ?\C-c] 'bat-run) + (define-key map [?\C-c ?\C-t] 'bat-template) + (define-key map [?\C-c ?\C-v] 'bat-run) + map)) + +(defvar bat-mode-syntax-table + (let ((table (make-syntax-table))) + ;; Beware: `w' should not be used for non-alphabetic chars. + (modify-syntax-entry ?~ "_" table) + (modify-syntax-entry ?% "." table) + (modify-syntax-entry ?- "_" table) + (modify-syntax-entry ?_ "_" table) + ;; FIXME: { and } can appear in identifiers? Really? + (modify-syntax-entry ?{ "_" table) + (modify-syntax-entry ?} "_" table) + (modify-syntax-entry ?\\ "." table) + table)) + +;; 4 User functions + +(defun bat-cmd-help (cmd) + "Show help for batch file command CMD." + (interactive "sHelp: ") + (if (string-equal cmd "net") + ;; FIXME: liable to quoting nightmare. Use call-process? + (shell-command "net /?") (shell-command (concat "help " cmd)))) + +(defun bat-run () + "Run a batch file." + (interactive) + ;; FIXME: liable to quoting nightmare. Use call/start-process? + (save-buffer) (shell-command buffer-file-name)) + +(defun bat-run-args (args) + "Run a batch file with ARGS." + (interactive "sArgs: ") + ;; FIXME: Use `compile'? + (shell-command (concat buffer-file-name " " args))) + +(defun bat-template () + "Insert minimal batch file template." + (interactive) + (goto-char (point-min)) (insert "@echo off\nsetlocal\n\n")) + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.\\(bat\\|cmd\\)\\'" . bat-mode)) + +;; 5 Main function + +;;;###autoload +(define-derived-mode bat-mode prog-mode "Bat" + "Major mode for editing DOS/Windows batch files.\n +Start a new script from `bat-template'. Read help pages for DOS commands +with `bat-cmd-help'. Navigate between sections using `imenu'. +Run script using `bat-run' and `bat-run-args'.\n +\\{bat-mode-map}" + (setq-local comment-start "rem ") + (setq-local font-lock-defaults + '(bat-font-lock-keywords nil t)) ; case-insensitive keywords + (setq-local imenu-generic-expression '((nil "^:[^:].*" 0))) + (setq-local outline-regexp ":[^:]")) + +(provide 'bat-mode) + +;;; bat-mode.el ends here diff --git a/lisp/progmodes/dos.el b/lisp/progmodes/dos.el deleted file mode 100644 index 593b5e9fc92..00000000000 --- a/lisp/progmodes/dos.el +++ /dev/null @@ -1,191 +0,0 @@ -;;; dos.el --- Major mode for editing Dos scripts - -;; Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc. - -;; Author: Arni Magnusson -;; Keywords: languages - -;; This file is part of GNU Emacs. - -;; GNU Emacs is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; GNU Emacs is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs. If not, see . - -;;; Commentary: -;; -;; Major mode for editing Dos scripts (batch files). Provides syntax -;; highlighting, a basic template, access to Dos help pages, imenu/outline -;; navigation, and the ability to run scripts from within Emacs. The syntax -;; groups for highlighting are: -;; -;; Face Example -;; dos-label-face :LABEL -;; font-lock-comment-face rem -;; font-lock-builtin-face copy -;; font-lock-keyword-face goto -;; font-lock-warning-face cp -;; font-lock-constant-face [call] prog -;; font-lock-variable-name-face %var% -;; font-lock-type-face -option -;; -;; Usage: -;; -;; See documentation of function `dos-mode'. -;; -;; Separate package `dos-indent' (Matthew Fidler) provides rudimentary -;; indentation, see http://www.emacswiki.org/emacs/dos-indent.el. -;; -;; Acknowledgements: -;; -;; Inspired by `batch-mode' (Agnar Renolen) and `cmd-mode' (Tadamegu Furukawa). - -;;; Code: - -;; 1 Preamble - -(defgroup dos nil - "Major mode for editing DOS/Windows batch files." - :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) - :group 'languages) - -;; 2 User variables - -(defface dos-label-face '((t :weight bold)) - "Font Lock mode face used to highlight labels in batch files." - :group 'dos) - -;; 3 Internal variables - -(defvar dos-font-lock-keywords - (eval-when-compile - (let ((COMMANDS - '("assoc" "at" "attrib" "cd" "cls" "color" "copy" "date" "del" "dir" - "doskey" "echo" "endlocal" "erase" "fc" "find" "findstr" "format" - "ftype" "label" "md" "mkdir" "more" "move" "net" "path" "pause" - "popd" "prompt" "pushd" "rd" "ren" "rename" "replace" "rmdir" "set" - "setlocal" "shift" "sort" "subst" "time" "title" "tree" "type" - "ver" "vol" "xcopy")) - (CONTROLFLOW - '("call" "cmd" "defined" "do" "else" "equ" "exist" "exit" "for" "geq" - "goto" "gtr" "if" "in" "leq" "lss" "neq" "not" "start")) - (UNIX - '("bash" "cat" "cp" "fgrep" "grep" "ls" "sed" "sh" "mv" "rm"))) - `(("\\<_\\(call\\|goto\\)\\_>[ \t]+%?\\([A-Za-z0-9-_\\:.]+\\)%?" - (2 font-lock-constant-face t)) - ("^[ \t]*\\(@?rem\\_>\\|::\\).*" - (0 font-lock-comment-face t)) - ("^:[^:].*" - . 'dos-label-face) - ("\\<_\\(defined\\|set\\)\\_>[ \t]*\\(\\w+\\)" - (2 font-lock-variable-name-face)) - ("%\\(\\w+\\)%?" - (1 font-lock-variable-name-face)) - ("!\\(\\w+\\)!?" ; delayed-expansion !variable! - (1 font-lock-variable-name-face)) - ("[ =][-/]+\\(\\w+\\)" - (1 font-lock-type-face append)) - (,(concat "\\_<" (regexp-opt COMMANDS) "\\_>") . font-lock-builtin-face) - (,(concat "\\_<" (regexp-opt CONTROLFLOW) "\\_>") - . font-lock-keyword-face) - (,(concat "\\_<" (regexp-opt UNIX) "\\_>") - . font-lock-warning-face))))) - -(defvar dos-menu - '("Dos" - ["Run" dos-run :help "Run script"] - ["Run with Args" dos-run-args :help "Run script with args"] - "--" - ["Imenu" imenu :help "Navigate with imenu"] - "--" - ["Template" dos-template :help "Insert template"] - "--" - ["Help (Command)" dos-cmd-help :help "Show help page for Dos command"] - ["Help (Mode)" dos-mode-help :help "Show help page for Emacs Dos Mode"])) - -(defvar dos-mode-map - (let ((map (make-sparse-keymap))) - (easy-menu-define nil map nil dos-menu) - (define-key map [?\C-c ?\C-.] 'dos-mode-help) - (define-key map [?\C-c ?\C-/] 'dos-cmd-help) ;FIXME: Why not C-c C-? ? - (define-key map [?\C-c ?\C-a] 'dos-run-args) - (define-key map [?\C-c ?\C-c] 'dos-run) - (define-key map [?\C-c ?\C-t] 'dos-template) - (define-key map [?\C-c ?\C-v] 'dos-run) - map)) - -(defvar dos-mode-syntax-table - (let ((table (make-syntax-table))) - ;; Beware: `w' should not be used for non-alphabetic chars. - (modify-syntax-entry ?~ "_" table) - (modify-syntax-entry ?% "." table) - (modify-syntax-entry ?- "_" table) - (modify-syntax-entry ?_ "_" table) - ;; FIXME: { and } can appear in identifiers? Really? - (modify-syntax-entry ?{ "_" table) - (modify-syntax-entry ?} "_" table) - (modify-syntax-entry ?\\ "." table) - table)) - -;; 4 User functions - -(defun dos-cmd-help (cmd) - "Show help for batch file command CMD." - (interactive "sHelp: ") - (if (string-equal cmd "net") - ;; FIXME: liable to quoting nightmare. Use call-process? - (shell-command "net /?") (shell-command (concat "help " cmd)))) - -(defun dos-mode-help () - "Show help page for `dos-mode'." - (interactive) - (describe-function 'dos-mode) - (switch-to-buffer "*Help*") (delete-other-windows) (message nil)) - -(defun dos-run () - "Run a batch file." - (interactive) - ;; FIXME: liable to quoting nightmare. Use call/start-process? - (save-buffer) (shell-command buffer-file-name)) - -(defun dos-run-args (args) - "Run a batch file with ARGS." - (interactive "sArgs: ") - ;; FIXME: Use `compile'? - (shell-command (concat buffer-file-name " " args))) - -(defun dos-template () - "Insert minimal batch file template." - (interactive) - (goto-char (point-min)) (insert "@echo off\nsetlocal\n\n")) - -;;;###autoload -(add-to-list 'auto-mode-alist '("\\.\\(bat\\|cmd\\)\\'" . dos-mode)) - -;; 5 Main function - -;;;###autoload -(define-derived-mode dos-mode prog-mode "Dos" - "Major mode for editing DOS/Windows batch files.\n -The `dos-mode-help' command shows this page.\n -Start a new script from `dos-template'. Read help pages for Dos commands -with `dos-cmd-help'. Navigate between sections using `imenu'. -Run script using `dos-run' and `dos-run-args'.\n -\\{dos-mode-map}" - (setq-local comment-start "rem ") - (setq-local font-lock-defaults - '(dos-font-lock-keywords nil t)) ; case-insensitive keywords - (setq-local imenu-generic-expression '((nil "^:[^:].*" 0))) - (setq-local outline-regexp ":[^:]")) - -(provide 'dos) - -;;; dos.el ends here