]> git.donarmstrong.com Git - lilypond.git/blob - server.el.patch
*** empty log message ***
[lilypond.git] / server.el.patch
1 From: Jan Nieuwenhuizen <janneke@gnu.org>
2 To: bug-gnu-emacs@gnu.org
3 Cc: Han-Wen <hanwen@cs.uu.nl>
4 Subject: Bugfix and feature for server.el
5 Date: Sun, 21 Jul 2002 00:44:32 +0200
6
7
8 Hi,
9
10 Find the following fix attached.  We had a problem with our
11 application that uses emaclient --no-wait to edit input files.
12
13 Emacs21 wants to revert buffers whenever they have been edited, which
14 is annoying.  And when it does revert the buffer, it does not use the
15 column argument of emacsclient; fixed.
16
17
18 Greeting,
19 Han-Wen and Jan.
20
21
22 ChangeLog:
23 2002-07-21  Jan Nieuwenhuizen  <janneke@gnu.org>
24
25         * server.el (server-process-filter): Cleanup stray if.  Add
26         'no-revert to file list entry when emacsclient was invoked with
27         '--no-wait'.
28         (server-visit-files): New function goto-line-column.  Accept
29         'no-revert option.  Bugfix: also goto column when reverting
30         buffer.
31
32 --- server.el.~1.78.~   Tue Dec 18 17:42:38 2001
33 +++ server.el   Sun Jul 21 00:30:29 2002
34 @@ -251,40 +251,43 @@ Prefix arg means just kill any existing 
35                        (substring request (match-beginning 0) (1- (match-end 0))))
36                       (pos 0))
37                   (setq request (substring request (match-end 0)))
38 -                 (if (string-match "\\`-nowait" arg)
39 -                     (setq nowait t)
40 -                   (cond
41 -                       ;; ARG is a line number option.
42 -                    ((string-match "\\`\\+[0-9]+\\'" arg)
43 +                 (cond
44 +                  ((string-match "\\`-nowait" arg)
45 +                   (setq nowait t))
46 +                  ;; ARG is a line number option.
47 +                  ((string-match "\\`\\+[0-9]+\\'" arg)
48                       (setq lineno (string-to-int (substring arg 1))))
49 -                    ;; ARG is line number:column option. 
50 -                    ((string-match "\\`+\\([0-9]+\\):\\([0-9]+\\)\\'" arg)
51 -                     (setq lineno (string-to-int (match-string 1 arg))
52 -                           columnno (string-to-int (match-string 2 arg))))
53 -                    (t
54 -                     ;; ARG is a file name.
55 -                     ;; Collapse multiple slashes to single slashes.
56 -                     (setq arg (command-line-normalize-file-name arg))
57 -                     ;; Undo the quoting that emacsclient does
58 -                     ;; for certain special characters.
59 -                     (while (string-match "&." arg pos)
60 -                       (setq pos (1+ (match-beginning 0)))
61 -                       (let ((nextchar (aref arg pos)))
62 -                         (cond ((= nextchar ?&)
63 -                                (setq arg (replace-match "&" t t arg)))
64 -                               ((= nextchar ?-)
65 -                                (setq arg (replace-match "-" t t arg)))
66 -                               (t
67 -                                (setq arg (replace-match " " t t arg))))))
68 -                     ;; Now decode the file name if necessary.
69 -                     (if coding-system
70 -                         (setq arg (decode-coding-string arg coding-system)))
71 -                     (setq files
72 -                           (cons (list arg lineno columnno)
73 -                                 files))
74 -                     (setq lineno 1)
75 -                     (setq columnno 0))))))
76 -             (run-hooks 'pre-command-hook)
77 +                  ;; ARG is line number:column option. 
78 +                  ((string-match "\\`+\\([0-9]+\\):\\([0-9]+\\)\\'" arg)
79 +                   (setq lineno (string-to-int (match-string 1 arg))
80 +                         columnno (string-to-int (match-string 2 arg))))
81 +                  (t
82 +                   ;; ARG is a file name.
83 +                   ;; Collapse multiple slashes to single slashes.
84 +                   (setq arg (command-line-normalize-file-name arg))
85 +                   ;; Undo the quoting that emacsclient does
86 +                   ;; for certain special characters.
87 +                   (while (string-match "&." arg pos)
88 +                     (setq pos (1+ (match-beginning 0)))
89 +                     (let ((nextchar (aref arg pos)))
90 +                       (cond ((= nextchar ?&)
91 +                              (setq arg (replace-match "&" t t arg)))
92 +                             ((= nextchar ?-)
93 +                              (setq arg (replace-match "-" t t arg)))
94 +                             (t
95 +                              (setq arg (replace-match " " t t arg))))))
96 +                   ;; Now decode the file name if necessary.
97 +                   (if coding-system
98 +                       (setq arg (decode-coding-string arg coding-system)))
99 +                   (setq files
100 +                         ;; When invoking emacsclient with --no-wait, we are
101 +                         ;; typically `moving around' and editing the same file;
102 +                         ;; and do not want to revert.  Should make --no-revert
103 +                         ;; option for emacsclient?
104 +                         (cons (list arg lineno columnno (if nowait 'no-revert nil))
105 +                               files))
106 +                   (setq lineno 1)
107 +                   (setq columnno 0)))))
108               (server-visit-files files client nowait)
109               (run-hooks 'post-command-hook)
110               ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
111 @@ -309,6 +312,13 @@ Prefix arg means just kill any existing 
112  FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER).
113  NOWAIT non-nil means this client is not waiting for the results,
114  so don't mark these buffers specially, just visit them normally."
115 +
116 +  (defun goto-line-column (file-line-col)
117 +    (goto-line (nth 1 file-line-col))
118 +    (let ((column-number (nth 2 file-line-col)))
119 +      (if (> column-number 0)
120 +         (move-to-column (1- column-number)))))
121 +  
122    ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries.
123    (let (client-record (last-nonmenu-event t) (obuf (current-buffer)))
124      ;; Restore the current buffer afterward, but not using save-excursion,
125 @@ -322,7 +332,8 @@ so don't mark these buffers specially, j
126           (let* ((filen (car (car files)))
127                  (obuf (get-file-buffer filen)))
128             (push filen file-name-history)
129 -           (if (and obuf (set-buffer obuf))
130 +           (if (and obuf (set-buffer obuf)
131 +                    (not (memq 'no-revert (car files))))
132                 (progn
133                   (cond ((file-exists-p filen)
134                          (if (or (not (verify-visited-file-modtime obuf))
135 @@ -335,12 +346,9 @@ so don't mark these buffers specially, j
136                                       ", write buffer to file? "))
137                              (write-file filen))))
138                   (setq server-existing-buffer t)
139 -                 (goto-line (nth 1 (car files))))
140 +                 (goto-line-column (car files)))
141               (set-buffer (find-file-noselect filen))
142 -             (goto-line (nth 1 (car files)))
143 -             (let ((column-number (nth 2 (car files))))
144 -               (when (> column-number 0)
145 -                 (move-to-column (1- column-number))))
146 +             (goto-line-column (car files))
147               (run-hooks 'server-visit-hook)))
148           (if (not nowait)
149               (setq server-buffer-clients
150 @@ -404,8 +412,9 @@ or nil.  KILLED is t if we killed BUFFER
151             (unless for-killing
152               (when (and (not killed)
153                          server-kill-new-buffers
154 -                        (with-current-buffer buffer
155 -                          (not server-existing-buffer)))
156 +                        (save-excursion
157 +                          (set-buffer buffer)
158 +                          server-existing-buffer))
159                 (setq killed t)
160                 (bury-buffer buffer)
161                 (kill-buffer buffer))
162         
163