diff options
| author | Philipp Stephani | 2020-05-14 19:26:43 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2020-05-14 19:29:14 +0200 |
| commit | 406fb0746c8b54869302d50b2327333769b7604b (patch) | |
| tree | fb6a44b50edd627e9a031ab3f474e39c6e0b9af5 | |
| parent | 747e0a2523e474c76410430c40cb9b04500218d4 (diff) | |
| download | emacs-406fb0746c8b54869302d50b2327333769b7604b.tar.gz emacs-406fb0746c8b54869302d50b2327333769b7604b.zip | |
Fix documentation related to 'command-switch-alist'.
While there, add a unit test to verify the behavior.
* doc/lispref/os.texi (Command-Line Arguments): Fix documentation: the
option string in 'command-switch-alist' does include leading hyphens.
Also mention that 'command-switch-alist' parsing ignores equals signs
in options.
* test/lisp/startup-tests.el
(startup-tests/command-switch-alist): New unit test.
| -rw-r--r-- | doc/lispref/os.texi | 10 | ||||
| -rw-r--r-- | test/lisp/startup-tests.el | 47 |
2 files changed, 56 insertions, 1 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 92684c8993e..97b8b532fea 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -613,7 +613,7 @@ The elements of the @code{command-switch-alist} look like this: | |||
| 613 | @end example | 613 | @end example |
| 614 | 614 | ||
| 615 | The @sc{car}, @var{option}, is a string, the name of a command-line | 615 | The @sc{car}, @var{option}, is a string, the name of a command-line |
| 616 | option (not including the initial hyphen). The @var{handler-function} | 616 | option (including the initial hyphen). The @var{handler-function} |
| 617 | is called to handle @var{option}, and receives the option name as its | 617 | is called to handle @var{option}, and receives the option name as its |
| 618 | sole argument. | 618 | sole argument. |
| 619 | 619 | ||
| @@ -623,6 +623,14 @@ remaining command-line arguments in the variable | |||
| 623 | @code{command-line-args-left} (see below). (The entire list of | 623 | @code{command-line-args-left} (see below). (The entire list of |
| 624 | command-line arguments is in @code{command-line-args}.) | 624 | command-line arguments is in @code{command-line-args}.) |
| 625 | 625 | ||
| 626 | Note that the handling of @code{command-switch-alist} doesn't treat | ||
| 627 | equals signs in @var{option} specially. That is, if there's an option | ||
| 628 | like @code{--name=value} on the command line, then only a | ||
| 629 | @code{command-switch-alist} member whose @code{car} is literally | ||
| 630 | @code{--name=value} will match this option. If you want to parse such | ||
| 631 | options, you need to use @code{command-line-functions} instead (see | ||
| 632 | below). | ||
| 633 | |||
| 626 | The command-line arguments are parsed by the @code{command-line-1} | 634 | The command-line arguments are parsed by the @code{command-line-1} |
| 627 | function in the @file{startup.el} file. See also @ref{Emacs | 635 | function in the @file{startup.el} file. See also @ref{Emacs |
| 628 | Invocation, , Command Line Arguments for Emacs Invocation, emacs, The | 636 | Invocation, , Command Line Arguments for Emacs Invocation, emacs, The |
diff --git a/test/lisp/startup-tests.el b/test/lisp/startup-tests.el new file mode 100644 index 00000000000..314ffc93e4a --- /dev/null +++ b/test/lisp/startup-tests.el | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | ;;; startup-tests.el --- unit tests for startup.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2020 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Philipp Stephani <phst@google.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;; Unit tests for startup.el. | ||
| 25 | |||
| 26 | ;;; Code: | ||
| 27 | |||
| 28 | (ert-deftest startup-tests/command-switch-alist () | ||
| 29 | (let* ((foo-args ()) (bar-args ()) | ||
| 30 | (command-switch-alist | ||
| 31 | (list (cons "--foo" | ||
| 32 | (lambda (arg) | ||
| 33 | (ert-info ("Processing argument --foo") | ||
| 34 | (push arg foo-args) | ||
| 35 | (should (equal command-line-args-left | ||
| 36 | '("value" "--bar=value"))) | ||
| 37 | (pop command-line-args-left)))) | ||
| 38 | (cons "--bar=value" | ||
| 39 | (lambda (arg) | ||
| 40 | (ert-info ("Processing argument --bar") | ||
| 41 | (push arg bar-args) | ||
| 42 | (should-not command-line-args-left))))))) | ||
| 43 | (command-line-1 '("--foo" "value" "--bar=value")) | ||
| 44 | (should (equal foo-args '("--foo"))) | ||
| 45 | (should (equal bar-args '("--bar=value"))))) | ||
| 46 | |||
| 47 | ;;; startup-tests.el ends here | ||