changeset 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 b0683497550c
children 299387a1f305
files lisp/ChangeLog lisp/server.el
diffstat 2 files changed, 41 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Jan 16 16:17:53 2008 +0000
+++ b/lisp/ChangeLog	Wed Jan 16 16:21:08 2008 +0000
@@ -1,5 +1,12 @@
 2008-01-16  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* server.el (server-process-filter): Replace lineno and columnnno
+	which defaulted to 1&0 with filepos which defaults to nil.
+	(server-goto-line-column): Only receive the filepos.
+	Only move if filepos is non-nil.
+	(server-visit-files): Slight restructure to consolidate two calls to
+	server-goto-line-column into just one.
+
 	* nxml/nxml-mode.el (nxml-mode): Use mode-line-process to indicate
 	the use of degraded mode.
 	(nxml-degrade): Don't change mode-name.
--- a/lisp/server.el	Wed Jan 16 16:17:53 2008 +0000
+++ b/lisp/server.el	Wed Jan 16 16:21:08 2008 +0000
@@ -805,8 +805,7 @@
                 (tty-name nil)       ;nil, `window-system', or the tty name.
                 tty-type             ;string.
 		(files nil)
-		(lineno 1)
-		(columnno 0)
+                (filepos nil)
 		command-line-args-left
 		arg)
 	    ;; Remove this line from STRING.
@@ -876,9 +875,9 @@
                        (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?"
                                      (car command-line-args-left)))
 		  (setq arg (pop command-line-args-left))
-		  (setq lineno (string-to-number (match-string 1 arg))
-			columnno (if (null (match-end 2)) 0
-                                   (string-to-number (match-string 2 arg)))))
+		  (setq filepos
+                        (cons (string-to-number (match-string 1 arg))
+                              (string-to-number (or (match-string 2 arg) "")))))
 
 		 ;; -file FILENAME:  Load the given file.
 		 ((and (equal "-file" arg)
@@ -887,11 +886,10 @@
 		    (if coding-system
 			(setq file (decode-coding-string file coding-system)))
 		    (setq file (command-line-normalize-file-name file))
-		    (push (list file lineno columnno) files)
-		    (server-log (format "New file: %s (%d:%d)"
-                                        file lineno columnno) proc))
-		  (setq lineno 1
-			columnno 0))
+		    (push (cons file filepos) files)
+		    (server-log (format "New file: %s %s"
+                                        file (or filepos "")) proc))
+		  (setq filepos nil))
 
 		 ;; -eval EXPR:  Evaluate a Lisp expression.
 		 ((and (equal "-eval" arg)
@@ -901,8 +899,7 @@
 			(setq expr (decode-coding-string expr coding-system)))
                     (push (lambda () (server-eval-and-print expr proc))
                           commands)
-		    (setq lineno 1
-			  columnno 0)))
+		    (setq filepos nil)))
 
 		 ;; -env NAME=VALUE:  An environment variable.
 		 ((and (equal "-env" arg) command-line-args-left)
@@ -991,18 +988,19 @@
     (server-log (error-message-string err) proc)
     (delete-process proc)))
 
-(defun server-goto-line-column (file-line-col)
-  "Move point to the position indicated in FILE-LINE-COL.
-FILE-LINE-COL should be a three-element list as described in
-`server-visit-files'."
-  (goto-line (nth 1 file-line-col))
-  (let ((column-number (nth 2 file-line-col)))
-    (when (> column-number 0)
-      (move-to-column (1- column-number)))))
+(defun server-goto-line-column (line-col)
+  "Move point to the position indicated in LINE-COL.
+LINE-COL should be a pair (LINE . COL)."
+  (when line-col
+    (goto-line (car line-col))
+    (let ((column-number (cdr line-col)))
+      (when (> column-number 0)
+        (move-to-column (1- column-number))))))
 
 (defun server-visit-files (files proc &optional nowait)
   "Find FILES and return a list of buffers created.
-FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER).
+FILES is an alist whose elements are (FILENAME . FILEPOS)
+where FILEPOS can be nil or a pair (LINENUMBER . COLUMNNUMBER).
 PROC is the client that requested this operation.
 NOWAIT non-nil means this client is not waiting for the results,
 so don't mark these buffers specially, just visit them normally."
@@ -1021,22 +1019,21 @@
 	       (filen (car file))
 	       (obuf (get-file-buffer filen)))
 	  (add-to-history 'file-name-history filen)
-	  (if (and obuf (set-buffer obuf))
-	      (progn
-		(cond ((file-exists-p filen)
-		       (when (not (verify-visited-file-modtime obuf))
-			 (revert-buffer t nil)))
-		      (t
-		       (when (y-or-n-p
-			      (concat "File no longer exists: " filen
-				      ", write buffer to file? "))
-			 (write-file filen))))
-		(unless server-buffer-clients
-		  (setq server-existing-buffer t))
-		(server-goto-line-column file))
-	    (set-buffer (find-file-noselect filen))
-	    (server-goto-line-column file)
-	    (run-hooks 'server-visit-hook)))
+	  (if (null obuf)
+              (set-buffer (find-file-noselect filen))
+            (set-buffer obuf)
+            (cond ((file-exists-p filen)
+                   (when (not (verify-visited-file-modtime obuf))
+                     (revert-buffer t nil)))
+                  (t
+                   (when (y-or-n-p
+                          (concat "File no longer exists: " filen
+                                  ", write buffer to file? "))
+                     (write-file filen))))
+            (unless server-buffer-clients
+              (setq server-existing-buffer t)))
+          (server-goto-line-column (cdr file))
+          (run-hooks 'server-visit-hook))
 	(unless nowait
 	  ;; When the buffer is killed, inform the clients.
 	  (add-hook 'kill-buffer-hook 'server-kill-buffer nil t)