comparison lisp/server.el @ 87794:42624d4f31ed

(server-process-filter): Replace lineno and columnnno which defaulted to 1&0 with filepos which defaults to nil. (server-goto-line-column): Don't move if filepos is nil. (server-visit-files): Slight restructure to consolidate two calls to server-goto-line-column into just one.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 16 Jan 2008 16:21:08 +0000
parents 04772d747469
children 5350f7d1e7aa
comparison
equal deleted inserted replaced
87793:b0683497550c 87794:42624d4f31ed
803 (commands ()) 803 (commands ())
804 dir 804 dir
805 (tty-name nil) ;nil, `window-system', or the tty name. 805 (tty-name nil) ;nil, `window-system', or the tty name.
806 tty-type ;string. 806 tty-type ;string.
807 (files nil) 807 (files nil)
808 (lineno 1) 808 (filepos nil)
809 (columnno 0)
810 command-line-args-left 809 command-line-args-left
811 arg) 810 arg)
812 ;; Remove this line from STRING. 811 ;; Remove this line from STRING.
813 (setq string (substring string (match-end 0))) 812 (setq string (substring string (match-end 0)))
814 (setq command-line-args-left 813 (setq command-line-args-left
874 ((and (equal "-position" arg) 873 ((and (equal "-position" arg)
875 command-line-args-left 874 command-line-args-left
876 (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?" 875 (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?"
877 (car command-line-args-left))) 876 (car command-line-args-left)))
878 (setq arg (pop command-line-args-left)) 877 (setq arg (pop command-line-args-left))
879 (setq lineno (string-to-number (match-string 1 arg)) 878 (setq filepos
880 columnno (if (null (match-end 2)) 0 879 (cons (string-to-number (match-string 1 arg))
881 (string-to-number (match-string 2 arg))))) 880 (string-to-number (or (match-string 2 arg) "")))))
882 881
883 ;; -file FILENAME: Load the given file. 882 ;; -file FILENAME: Load the given file.
884 ((and (equal "-file" arg) 883 ((and (equal "-file" arg)
885 command-line-args-left) 884 command-line-args-left)
886 (let ((file (pop command-line-args-left))) 885 (let ((file (pop command-line-args-left)))
887 (if coding-system 886 (if coding-system
888 (setq file (decode-coding-string file coding-system))) 887 (setq file (decode-coding-string file coding-system)))
889 (setq file (command-line-normalize-file-name file)) 888 (setq file (command-line-normalize-file-name file))
890 (push (list file lineno columnno) files) 889 (push (cons file filepos) files)
891 (server-log (format "New file: %s (%d:%d)" 890 (server-log (format "New file: %s %s"
892 file lineno columnno) proc)) 891 file (or filepos "")) proc))
893 (setq lineno 1 892 (setq filepos nil))
894 columnno 0))
895 893
896 ;; -eval EXPR: Evaluate a Lisp expression. 894 ;; -eval EXPR: Evaluate a Lisp expression.
897 ((and (equal "-eval" arg) 895 ((and (equal "-eval" arg)
898 command-line-args-left) 896 command-line-args-left)
899 (lexical-let ((expr (pop command-line-args-left))) 897 (lexical-let ((expr (pop command-line-args-left)))
900 (if coding-system 898 (if coding-system
901 (setq expr (decode-coding-string expr coding-system))) 899 (setq expr (decode-coding-string expr coding-system)))
902 (push (lambda () (server-eval-and-print expr proc)) 900 (push (lambda () (server-eval-and-print expr proc))
903 commands) 901 commands)
904 (setq lineno 1 902 (setq filepos nil)))
905 columnno 0)))
906 903
907 ;; -env NAME=VALUE: An environment variable. 904 ;; -env NAME=VALUE: An environment variable.
908 ((and (equal "-env" arg) command-line-args-left) 905 ((and (equal "-env" arg) command-line-args-left)
909 (let ((var (pop command-line-args-left))) 906 (let ((var (pop command-line-args-left)))
910 ;; XXX Variables should be encoded as in getenv/setenv. 907 ;; XXX Variables should be encoded as in getenv/setenv.
989 proc (concat "-error " (server-quote-arg 986 proc (concat "-error " (server-quote-arg
990 (error-message-string err)))) 987 (error-message-string err))))
991 (server-log (error-message-string err) proc) 988 (server-log (error-message-string err) proc)
992 (delete-process proc))) 989 (delete-process proc)))
993 990
994 (defun server-goto-line-column (file-line-col) 991 (defun server-goto-line-column (line-col)
995 "Move point to the position indicated in FILE-LINE-COL. 992 "Move point to the position indicated in LINE-COL.
996 FILE-LINE-COL should be a three-element list as described in 993 LINE-COL should be a pair (LINE . COL)."
997 `server-visit-files'." 994 (when line-col
998 (goto-line (nth 1 file-line-col)) 995 (goto-line (car line-col))
999 (let ((column-number (nth 2 file-line-col))) 996 (let ((column-number (cdr line-col)))
1000 (when (> column-number 0) 997 (when (> column-number 0)
1001 (move-to-column (1- column-number))))) 998 (move-to-column (1- column-number))))))
1002 999
1003 (defun server-visit-files (files proc &optional nowait) 1000 (defun server-visit-files (files proc &optional nowait)
1004 "Find FILES and return a list of buffers created. 1001 "Find FILES and return a list of buffers created.
1005 FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER). 1002 FILES is an alist whose elements are (FILENAME . FILEPOS)
1003 where FILEPOS can be nil or a pair (LINENUMBER . COLUMNNUMBER).
1006 PROC is the client that requested this operation. 1004 PROC is the client that requested this operation.
1007 NOWAIT non-nil means this client is not waiting for the results, 1005 NOWAIT non-nil means this client is not waiting for the results,
1008 so don't mark these buffers specially, just visit them normally." 1006 so don't mark these buffers specially, just visit them normally."
1009 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. 1007 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries.
1010 (let ((last-nonmenu-event t) client-record) 1008 (let ((last-nonmenu-event t) client-record)
1019 (let* ((minibuffer-auto-raise (or server-raise-frame 1017 (let* ((minibuffer-auto-raise (or server-raise-frame
1020 minibuffer-auto-raise)) 1018 minibuffer-auto-raise))
1021 (filen (car file)) 1019 (filen (car file))
1022 (obuf (get-file-buffer filen))) 1020 (obuf (get-file-buffer filen)))
1023 (add-to-history 'file-name-history filen) 1021 (add-to-history 'file-name-history filen)
1024 (if (and obuf (set-buffer obuf)) 1022 (if (null obuf)
1025 (progn 1023 (set-buffer (find-file-noselect filen))
1026 (cond ((file-exists-p filen) 1024 (set-buffer obuf)
1027 (when (not (verify-visited-file-modtime obuf)) 1025 (cond ((file-exists-p filen)
1028 (revert-buffer t nil))) 1026 (when (not (verify-visited-file-modtime obuf))
1029 (t 1027 (revert-buffer t nil)))
1030 (when (y-or-n-p 1028 (t
1031 (concat "File no longer exists: " filen 1029 (when (y-or-n-p
1032 ", write buffer to file? ")) 1030 (concat "File no longer exists: " filen
1033 (write-file filen)))) 1031 ", write buffer to file? "))
1034 (unless server-buffer-clients 1032 (write-file filen))))
1035 (setq server-existing-buffer t)) 1033 (unless server-buffer-clients
1036 (server-goto-line-column file)) 1034 (setq server-existing-buffer t)))
1037 (set-buffer (find-file-noselect filen)) 1035 (server-goto-line-column (cdr file))
1038 (server-goto-line-column file) 1036 (run-hooks 'server-visit-hook))
1039 (run-hooks 'server-visit-hook)))
1040 (unless nowait 1037 (unless nowait
1041 ;; When the buffer is killed, inform the clients. 1038 ;; When the buffer is killed, inform the clients.
1042 (add-hook 'kill-buffer-hook 'server-kill-buffer nil t) 1039 (add-hook 'kill-buffer-hook 'server-kill-buffer nil t)
1043 (push proc server-buffer-clients)) 1040 (push proc server-buffer-clients))
1044 (push (current-buffer) client-record))) 1041 (push (current-buffer) client-record)))