diff options
| author | Samer Masterson | 2015-08-10 11:09:50 -0700 |
|---|---|---|
| committer | Samer Masterson | 2015-08-10 11:14:27 -0700 |
| commit | 5cd6c08998118a057baf89fedcbcee889e606fa2 (patch) | |
| tree | 01242fd988bc0feb7f7ccc9a57a5d4fbc56f30fb | |
| parent | 3985a21b5205d65bece84d1ba74f44478db78d91 (diff) | |
| download | emacs-5cd6c08998118a057baf89fedcbcee889e606fa2.tar.gz emacs-5cd6c08998118a057baf89fedcbcee889e606fa2.zip | |
Set file buffer as current for "--file"
* lisp/startup.el (command-line-1): Set file buffer as current before
it is displayed so it can be used with options like
"--eval". (Bug#21095)
| -rw-r--r-- | lisp/startup.el | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/lisp/startup.el b/lisp/startup.el index cfe22690df8..11d22124c0c 100644 --- a/lisp/startup.el +++ b/lisp/startup.el | |||
| @@ -2160,9 +2160,12 @@ A fancy display is used on graphic displays, normal otherwise." | |||
| 2160 | ;; which includes files parsed from the command line arguments and | 2160 | ;; which includes files parsed from the command line arguments and |
| 2161 | ;; `initial-buffer-choice'. All of the display logic happens at the | 2161 | ;; `initial-buffer-choice'. All of the display logic happens at the |
| 2162 | ;; end of this `let'. As files as processed from the command line | 2162 | ;; end of this `let'. As files as processed from the command line |
| 2163 | ;; arguments, their buffers are prepended to `displayable-buffers' | 2163 | ;; arguments, their buffers are prepended to `displayable-buffers'. |
| 2164 | ;; but they are not displayed until command line parsing has | 2164 | ;; In order for options like "--eval" to work with the "--file" arg, |
| 2165 | ;; finished. | 2165 | ;; the file buffers are set as the current buffer as they are seen |
| 2166 | ;; on the command line (so "emacs --batch --file a --file b | ||
| 2167 | ;; --eval='(message "%s" (buffer-name))'" will print "b"), but this | ||
| 2168 | ;; does not affect the final displayed state of the buffers. | ||
| 2166 | (let ((displayable-buffers nil)) | 2169 | (let ((displayable-buffers nil)) |
| 2167 | ;; This `let' processes the command line arguments. | 2170 | ;; This `let' processes the command line arguments. |
| 2168 | (let ((command-line-args-left args-left)) | 2171 | (let ((command-line-args-left args-left)) |
| @@ -2193,10 +2196,11 @@ A fancy display is used on graphic displays, normal otherwise." | |||
| 2193 | command-switch-alist))) | 2196 | command-switch-alist))) |
| 2194 | (line 0) | 2197 | (line 0) |
| 2195 | (column 0) | 2198 | (column 0) |
| 2196 | ;; `process-file-arg' opens a file buffer for `name' | 2199 | ;; `process-file-arg' opens a file buffer for `name', |
| 2197 | ;; without switching to the buffer, adds the buffer to | 2200 | ;; sets that buffer as the current buffer without |
| 2201 | ;; displaying it, adds the buffer to | ||
| 2198 | ;; `displayable-buffers', and puts the point at | 2202 | ;; `displayable-buffers', and puts the point at |
| 2199 | ;; `line':`column'. `line' and `column' are both reset | 2203 | ;; `line':`column'. `line' and `column' are both reset |
| 2200 | ;; to zero when `process-file-arg' returns. | 2204 | ;; to zero when `process-file-arg' returns. |
| 2201 | (process-file-arg | 2205 | (process-file-arg |
| 2202 | (lambda (name) | 2206 | (lambda (name) |
| @@ -2209,14 +2213,19 @@ nil default-directory" name) | |||
| 2209 | dir)) | 2213 | dir)) |
| 2210 | (buf (find-file-noselect file))) | 2214 | (buf (find-file-noselect file))) |
| 2211 | (setq displayable-buffers (cons buf displayable-buffers)) | 2215 | (setq displayable-buffers (cons buf displayable-buffers)) |
| 2212 | (with-current-buffer buf | 2216 | ;; Set the file buffer to the current buffer so |
| 2213 | (unless (zerop line) | 2217 | ;; that it will be used with "--eval" and |
| 2214 | (goto-char (point-min)) | 2218 | ;; similar options. |
| 2215 | (forward-line (1- line))) | 2219 | (set-buffer buf) |
| 2216 | (setq line 0) | 2220 | ;; Put the point at `line':`column' in the file |
| 2217 | (unless (< column 1) | 2221 | ;; buffer, and reset `line' and `column' to 0. |
| 2218 | (move-to-column (1- column))) | 2222 | (unless (zerop line) |
| 2219 | (setq column 0))))))) | 2223 | (goto-char (point-min)) |
| 2224 | (forward-line (1- line))) | ||
| 2225 | (setq line 0) | ||
| 2226 | (unless (< column 1) | ||
| 2227 | (move-to-column (1- column))) | ||
| 2228 | (setq column 0)))))) | ||
| 2220 | 2229 | ||
| 2221 | ;; Add the long X options to longopts. | 2230 | ;; Add the long X options to longopts. |
| 2222 | (dolist (tem command-line-x-option-alist) | 2231 | (dolist (tem command-line-x-option-alist) |