comparison lisp/server.el @ 86380:2f0cad6a4f81

* server.el (server-process-filter): Use `command-line-args-left'
author David Kastrup <dak@gnu.org>
date Fri, 23 Nov 2007 23:59:19 +0000
parents e83e0513df1b
children 655d101f4e6b 53108e6cea98
comparison
equal deleted inserted replaced
86379:2ac1a9b70580 86380:2f0cad6a4f81
809 dir 809 dir
810 (tty-name nil) ;nil, `window-system', or the tty name. 810 (tty-name nil) ;nil, `window-system', or the tty name.
811 tty-type ;string. 811 tty-type ;string.
812 (files nil) 812 (files nil)
813 (lineno 1) 813 (lineno 1)
814 (columnno 0)) 814 (columnno 0)
815 command-line-args-left
816 arg)
815 ;; Remove this line from STRING. 817 ;; Remove this line from STRING.
816 (setq string (substring string (match-end 0))) 818 (setq string (substring string (match-end 0)))
817 (while (string-match " *[^ ]* " request) 819 (setq command-line-args-left
818 (let ((arg (substring request (match-beginning 0) 820 (mapcar 'server-unquote-arg (split-string request " " t)))
819 (1- (match-end 0))))) 821 (while (setq arg (pop command-line-args-left))
820 (setq request (substring request (match-end 0)))
821 (cond 822 (cond
822 ;; -version CLIENT-VERSION: obsolete at birth. 823 ;; -version CLIENT-VERSION: obsolete at birth.
823 ((and (equal "-version" arg) (string-match "[^ ]+ " request)) 824 ((and (equal "-version" arg) command-line-args-left)
824 (setq request (substring request (match-end 0)))) 825 (pop command-line-args-left))
825 826
826 ;; -nowait: Emacsclient won't wait for a result. 827 ;; -nowait: Emacsclient won't wait for a result.
827 ((equal "-nowait" arg) (setq nowait t)) 828 ((equal "-nowait" arg) (setq nowait t))
828 829
829 ;; -current-frame: Don't create frames. 830 ;; -current-frame: Don't create frames.
830 ((equal "-current-frame" arg) (setq tty-name nil)) 831 ((equal "-current-frame" arg) (setq tty-name nil))
831 832
832 ;; -display DISPLAY: 833 ;; -display DISPLAY:
833 ;; Open X frames on the given display instead of the default. 834 ;; Open X frames on the given display instead of the default.
834 ((and (equal "-display" arg) 835 ((and (equal "-display" arg) command-line-args-left)
835 (string-match "\\([^ ]*\\) " request)) 836 (setq display (pop command-line-args-left)))
836 (setq display (match-string 1 request))
837 (setq request (substring request (match-end 0))))
838 837
839 ;; -window-system: Open a new X frame. 838 ;; -window-system: Open a new X frame.
840 ((equal "-window-system" arg) 839 ((equal "-window-system" arg)
841 (setq dontkill t) 840 (setq dontkill t)
842 (setq tty-name 'window-system)) 841 (setq tty-name 'window-system))
861 (suspend-tty terminal))) 860 (suspend-tty terminal)))
862 commands))) 861 commands)))
863 862
864 ;; -ignore COMMENT: Noop; useful for debugging emacsclient. 863 ;; -ignore COMMENT: Noop; useful for debugging emacsclient.
865 ;; (The given comment appears in the server log.) 864 ;; (The given comment appears in the server log.)
866 ((and (equal "-ignore" arg) (string-match "[^ ]* " request)) 865 ((and (equal "-ignore" arg) command-line-args-left
867 (setq dontkill t 866 (setq dontkill t)
868 request (substring request (match-end 0)))) 867 (pop command-line-args-left)))
869 868
870 ;; -tty DEVICE-NAME TYPE: Open a new tty frame at the client. 869 ;; -tty DEVICE-NAME TYPE: Open a new tty frame at the client.
871 ((and (equal "-tty" arg) 870 ((and (equal "-tty" arg)
872 (string-match "\\([^ ]*\\) \\([^ ]*\\) " request)) 871 (cdr command-line-args-left))
873 (setq tty-name (match-string 1 request)) 872 (setq tty-name (pop command-line-args-left)
874 (setq tty-type (match-string 2 request)) 873 tty-type (pop command-line-args-left)
875 (setq dontkill t) 874 dontkill t))
876 (setq request (substring request (match-end 0))))
877 875
878 ;; -position LINE[:COLUMN]: Set point to the given 876 ;; -position LINE[:COLUMN]: Set point to the given
879 ;; position in the next file. 877 ;; position in the next file.
880 ((and (equal "-position" arg) 878 ((and (equal "-position" arg)
881 (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)? " 879 command-line-args-left
882 request)) 880 (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?"
883 (setq lineno (string-to-number (match-string 1 request)) 881 (car command-line-args-left)))
882 (setq arg (pop command-line-args-left))
883 (setq lineno (string-to-number (match-string 1 arg))
884 columnno (if (null (match-end 2)) 0 884 columnno (if (null (match-end 2)) 0
885 (string-to-number (match-string 2 request))) 885 (string-to-number (match-string 2 arg)))))
886 request (substring request (match-end 0))))
887 886
888 ;; -file FILENAME: Load the given file. 887 ;; -file FILENAME: Load the given file.
889 ((and (equal "-file" arg) 888 ((and (equal "-file" arg)
890 (string-match "\\([^ ]+\\) " request)) 889 command-line-args-left)
891 (let ((file (server-unquote-arg (match-string 1 request)))) 890 (let ((file (pop command-line-args-left)))
892 (setq request (substring request (match-end 0)))
893 (if coding-system 891 (if coding-system
894 (setq file (decode-coding-string file coding-system))) 892 (setq file (decode-coding-string file coding-system)))
895 (setq file (command-line-normalize-file-name file)) 893 (setq file (command-line-normalize-file-name file))
896 (push (list file lineno columnno) files) 894 (push (list file lineno columnno) files)
897 (server-log (format "New file: %s (%d:%d)" 895 (server-log (format "New file: %s (%d:%d)"
899 (setq lineno 1 897 (setq lineno 1
900 columnno 0)) 898 columnno 0))
901 899
902 ;; -eval EXPR: Evaluate a Lisp expression. 900 ;; -eval EXPR: Evaluate a Lisp expression.
903 ((and (equal "-eval" arg) 901 ((and (equal "-eval" arg)
904 (string-match "\\([^ ]+\\) " request)) 902 command-line-args-left)
905 (lexical-let ((expr (server-unquote-arg 903 (lexical-let ((expr (pop command-line-args-left)))
906 (match-string 1 request))))
907 (setq request (substring request (match-end 0)))
908 (if coding-system 904 (if coding-system
909 (setq expr (decode-coding-string expr coding-system))) 905 (setq expr (decode-coding-string expr coding-system)))
910 (push (lambda () (server-eval-and-print expr proc)) 906 (push (lambda () (server-eval-and-print expr proc))
911 commands) 907 commands)
912 (setq lineno 1 908 (setq lineno 1
913 columnno 0))) 909 columnno 0)))
914 910
915 ;; -env NAME=VALUE: An environment variable. 911 ;; -env NAME=VALUE: An environment variable.
916 ((and (equal "-env" arg) (string-match "\\([^ ]+\\) " request)) 912 ((and (equal "-env" arg) command-line-args-left)
917 (let ((var (server-unquote-arg (match-string 1 request)))) 913 (let ((var (pop command-line-args-left)))
918 ;; XXX Variables should be encoded as in getenv/setenv. 914 ;; XXX Variables should be encoded as in getenv/setenv.
919 (setq request (substring request (match-end 0)))
920 (process-put proc 'env 915 (process-put proc 'env
921 (cons var (process-get proc 'env))))) 916 (cons var (process-get proc 'env)))))
922 917
923 ;; -dir DIRNAME: The cwd of the emacsclient process. 918 ;; -dir DIRNAME: The cwd of the emacsclient process.
924 ((and (equal "-dir" arg) (string-match "\\([^ ]+\\) " request)) 919 ((and (equal "-dir" arg) command-line-args-left)
925 (setq dir (server-unquote-arg (match-string 1 request))) 920 (setq dir (pop command-line-args-left))
926 (setq request (substring request (match-end 0)))
927 (if coding-system 921 (if coding-system
928 (setq dir (decode-coding-string dir coding-system))) 922 (setq dir (decode-coding-string dir coding-system)))
929 (setq dir (command-line-normalize-file-name dir))) 923 (setq dir (command-line-normalize-file-name dir)))
930 924
931 ;; Unknown command. 925 ;; Unknown command.
932 (t (error "Unknown command: %s" arg))))) 926 (t (error "Unknown command: %s" arg))))
933 927
934 (setq frame 928 (setq frame
935 (case tty-name 929 (case tty-name
936 ((nil) (if display (server-select-display display))) 930 ((nil) (if display (server-select-display display)))
937 ((window-system) 931 ((window-system)