Mercurial > emacs
comparison lisp/startup.el @ 16745:1975baf7f996
(command-line-1): Handle --visit and --find.
Handle -- as an option; treat what follows as a file name.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 26 Dec 1996 20:47:49 +0000 |
parents | 049c87a96dca |
children | ba46af9fd00d |
comparison
equal
deleted
inserted
replaced
16744:b91256aecd79 | 16745:1975baf7f996 |
---|---|
789 (if init-file-had-error | 789 (if init-file-had-error |
790 (sit-for 2)) | 790 (sit-for 2)) |
791 (let ((dir command-line-default-directory) | 791 (let ((dir command-line-default-directory) |
792 (file-count 0) | 792 (file-count 0) |
793 first-file-buffer | 793 first-file-buffer |
794 done | 794 tem |
795 just-files ;; t if this follows the magic -- option. | |
796 ;; This includes our standard options' long versions | |
797 ;; and long versions of what's on command-switch-alist. | |
798 (longopts | |
799 (append '(("--funcall") ("--load") ("--insert") ("--kill") | |
800 ("--directory") ("--eval") ("--find-file") ("--visit")) | |
801 (mapcar '(lambda (elt) | |
802 (list (concat "-" (car elt)))) | |
803 command-switch-alist))) | |
795 (line 0)) | 804 (line 0)) |
796 (while (and command-line-args-left (not done)) | 805 |
806 ;; Add the long X options to longopts. | |
807 (setq tem command-line-x-option-alist) | |
808 (while tem | |
809 (if (string-match "^--" (car (car tem))) | |
810 (setq longopts (cons (list (car (car tem))) longopts))) | |
811 (setq tem (cdr tem))) | |
812 | |
813 ;; Loop, processing options. | |
814 (while (and command-line-args-left) | |
797 (let* ((argi (car command-line-args-left)) | 815 (let* ((argi (car command-line-args-left)) |
798 (orig-argi argi) | 816 (orig-argi argi) |
799 ;; This includes our standard options' long versions | 817 argval completion |
800 ;; and long versions of what's on command-switch-alist. | |
801 (longopts | |
802 (append '(("--funcall") ("--load") ("--insert") ("--kill") | |
803 ("--directory") ("--eval")) | |
804 (mapcar '(lambda (elt) | |
805 (list (concat "-" (car elt)))) | |
806 command-switch-alist))) | |
807 tem argval completion | |
808 ;; List of directories specified in -L/--directory, | 818 ;; List of directories specified in -L/--directory, |
809 ;; in reverse of the order specified. | 819 ;; in reverse of the order specified. |
810 extra-load-path | 820 extra-load-path |
811 (initial-load-path load-path)) | 821 (initial-load-path load-path)) |
812 (setq command-line-args-left (cdr command-line-args-left)) | 822 (setq command-line-args-left (cdr command-line-args-left)) |
813 | 823 |
814 ;; Add the long X options to longopts. | 824 ;; Do preliminary decoding of the option. |
815 (setq tem command-line-x-option-alist) | 825 (if just-files |
816 (while tem | 826 ;; After --, don't look for options; treat all args as files. |
817 (if (string-match "^--" (car (car tem))) | 827 (setq argi "") |
818 (setq longopts (cons (list (car (car tem))) longopts))) | 828 ;; Convert long options to ordinary options |
819 (setq tem (cdr tem))) | 829 ;; and separate out an attached option argument into argval. |
820 | 830 (if (string-match "^--[^=]*=" argi) |
821 ;; Convert long options to ordinary options | 831 (setq argval (substring argi (match-end 0)) |
822 ;; and separate out an attached option argument into argval. | 832 argi (substring argi 0 (1- (match-end 0))))) |
823 (if (string-match "^--[^=]*=" argi) | 833 (if (equal argi "--") |
824 (setq argval (substring argi (match-end 0)) | 834 (setq completion nil) |
825 argi (substring argi 0 (1- (match-end 0))))) | 835 (setq completion (try-completion argi longopts))) |
826 (if (equal argi "--") | 836 (if (eq completion t) |
827 (setq completion nil) | 837 (setq argi (substring argi 1)) |
828 (setq completion (try-completion argi longopts))) | 838 (if (stringp completion) |
829 (if (eq completion t) | 839 (let ((elt (assoc completion longopts))) |
830 (setq argi (substring argi 1)) | 840 (or elt |
831 (if (stringp completion) | 841 (error "Option `%s' is ambiguous" argi)) |
832 (let ((elt (assoc completion longopts))) | 842 (setq argi (substring (car elt) 1))) |
833 (or elt | 843 (setq argval nil argi orig-argi)))) |
834 (error "Option `%s' is ambiguous" argi)) | |
835 (setq argi (substring (car elt) 1))) | |
836 (setq argval nil argi orig-argi))) | |
837 | 844 |
838 ;; Execute the option. | 845 ;; Execute the option. |
839 (cond ((setq tem (assoc argi command-switch-alist)) | 846 (cond ((setq tem (assoc argi command-switch-alist)) |
840 (if argval | 847 (if argval |
841 (let ((command-line-args-left | 848 (let ((command-line-args-left |
896 (setq line (string-to-int argi))) | 903 (setq line (string-to-int argi))) |
897 ((setq tem (assoc argi command-line-x-option-alist)) | 904 ((setq tem (assoc argi command-line-x-option-alist)) |
898 ;; Ignore X-windows options and their args if not using X. | 905 ;; Ignore X-windows options and their args if not using X. |
899 (setq command-line-args-left | 906 (setq command-line-args-left |
900 (nthcdr (nth 1 tem) command-line-args-left))) | 907 (nthcdr (nth 1 tem) command-line-args-left))) |
908 ((or (string-equal argi "-find-file") | |
909 (string-equal argi "-visit")) | |
910 ;; An explicit option to specify visiting a file. | |
911 (setq file-count (1+ file-count)) | |
912 (let ((file | |
913 (expand-file-name | |
914 (command-line-normalize-file-name orig-argi) | |
915 dir))) | |
916 (if (= file-count 1) | |
917 (setq first-file-buffer (find-file file)) | |
918 (find-file-other-window file))) | |
919 (or (zerop line) | |
920 (goto-line line)) | |
921 (setq line 0)) | |
901 ((equal argi "--") | 922 ((equal argi "--") |
902 (setq done t)) | 923 (setq just-files t)) |
903 (t | 924 (t |
904 ;; We have almost exhausted our options. See if the | 925 ;; We have almost exhausted our options. See if the |
905 ;; user has made any other command-line options available | 926 ;; user has made any other command-line options available |
906 (let ((hooks command-line-functions);; lrs 7/31/89 | 927 (let ((hooks command-line-functions);; lrs 7/31/89 |
907 (did-hook nil)) | 928 (did-hook nil)) |
912 ;; Ok, presume that the argument is a file name | 933 ;; Ok, presume that the argument is a file name |
913 (progn | 934 (progn |
914 (if (string-match "\\`-" argi) | 935 (if (string-match "\\`-" argi) |
915 (error "Unknown option `%s'" argi)) | 936 (error "Unknown option `%s'" argi)) |
916 (setq file-count (1+ file-count)) | 937 (setq file-count (1+ file-count)) |
917 (setq argi (command-line-normalize-file-name argi)) | 938 (let ((file |
918 (cond ((= file-count 1) | 939 (expand-file-name |
919 (setq first-file-buffer | 940 (command-line-normalize-file-name orig-argi) |
920 (find-file (expand-file-name argi dir)))) | 941 dir))) |
921 (t | 942 (if (= file-count 1) |
922 (find-file-other-window (expand-file-name argi dir)))) | 943 (setq first-file-buffer (find-file file)) |
944 (find-file-other-window file))) | |
923 (or (zerop line) | 945 (or (zerop line) |
924 (goto-line line)) | 946 (goto-line line)) |
925 (setq line 0)))))))) | 947 (setq line 0)))))))) |
926 ;; If 3 or more files visited, and not all visible, | 948 ;; If 3 or more files visited, and not all visible, |
927 ;; show user what they all are. | 949 ;; show user what they all are. |