*** trunk/lib-src/emacsclient.c 2013-03-13 19:48:00.017919000 -0400 --- my-work/lib-src/emacsclient.c 2013-03-13 19:48:16.237220000 -0400 *************** *** 129,134 **** --- 129,137 ---- /* Nonzero means don't wait for a response from Emacs. --no-wait. */ int nowait = 0; + /* Nonzero means file should be readonly and placed in view-mode. --readonly. */ + int readonly = 0; + /* Nonzero means don't print messages for successful operations. --quiet. */ int quiet = 0; *************** *** 173,178 **** --- 176,182 ---- struct option longopts[] = { { "no-wait", no_argument, NULL, 'n' }, + { "readonly", no_argument, NULL, 'r' }, { "quiet", no_argument, NULL, 'q' }, { "eval", no_argument, NULL, 'e' }, { "help", no_argument, NULL, 'H' }, *************** *** 519,524 **** --- 523,532 ---- nowait = 1; break; + case 'r': + readonly = 1; + break; + case 'e': eval = 1; break; *************** *** 644,649 **** --- 652,658 ---- Set the parameters of a new frame\n\ -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ -n, --no-wait Don't wait for the server to return\n\ + -r, --readonly Make the buffer readonly and enable view-mode\n\ -q, --quiet Don't display messages on success\n\ -d DISPLAY, --display=DISPLAY\n\ Visit the file in the given display\n\ *************** *** 1604,1609 **** --- 1613,1621 ---- if (nowait) send_to_emacs (emacs_socket, "-nowait "); + if (readonly) + send_to_emacs (emacs_socket, "-readonly "); + if (current_frame) send_to_emacs (emacs_socket, "-current-frame "); *** trunk/lisp/server.el 2013-03-02 22:36:33.309144000 -0500 --- my-work/lisp/server.el 2013-03-06 23:58:19.157146157 -0500 *************** *** 1050,1055 **** --- 1050,1056 ---- (or file-name-coding-system default-file-name-coding-system))) nowait ; t if emacsclient does not want to wait for us. + readonly ; t to view files in read-only/view-mode frame ; Frame opened for the client (if any). display ; Open frame on this display. parent-id ; Window ID for XEmbed *************** *** 1075,1080 **** --- 1076,1084 ---- ;; -nowait: Emacsclient won't wait for a result. (`"-nowait" (setq nowait t)) + ;; -readonly: place files in view-mode + (`"-readonly" (setq readonly t)) + ;; -current-frame: Don't create frames. (`"-current-frame" (setq use-current-frame t)) *************** *** 1233,1239 **** (let ((default-directory (if (and dir (file-directory-p dir)) dir default-directory))) ! (server-execute proc files nowait commands dontkill frame tty-name))))) (when (or frame files) --- 1237,1243 ---- (let ((default-directory (if (and dir (file-directory-p dir)) dir default-directory))) ! (server-execute proc files nowait readonly commands dontkill frame tty-name))))) (when (or frame files) *************** *** 1243,1249 **** ;; condition-case (error (server-return-error proc err)))) ! (defun server-execute (proc files nowait commands dontkill frame tty-name) ;; This is run from timers and process-filters, i.e. "asynchronously". ;; But w.r.t the user, this is not really asynchronous since the timer ;; is run after 0s and the process-filter is run in response to the --- 1247,1253 ---- ;; condition-case (error (server-return-error proc err)))) ! (defun server-execute (proc files nowait readonly commands dontkill frame tty-name) ;; This is run from timers and process-filters, i.e. "asynchronously". ;; But w.r.t the user, this is not really asynchronous since the timer ;; is run after 0s and the process-filter is run in response to the *************** *** 1253,1259 **** ;; including code that needs to wait. (with-local-quit (condition-case err ! (let ((buffers (server-visit-files files proc nowait))) (mapc 'funcall (nreverse commands)) ;; If we were told only to open a new client, obey --- 1257,1263 ---- ;; including code that needs to wait. (with-local-quit (condition-case err ! (let ((buffers (server-visit-files files proc nowait readonly))) (mapc 'funcall (nreverse commands)) ;; If we were told only to open a new client, obey *************** *** 1319,1331 **** (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 . 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." ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. (let ((last-nonmenu-event t) client-record) ;; Restore the current buffer afterward, but not using save-excursion, --- 1323,1337 ---- (when (> column-number 0) (move-to-column (1- column-number)))))) ! (defun server-visit-files (files proc &optional nowait readonly) "Find FILES and return a list of buffers created. 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. ! READONLY non-nil means place the file in `view-mode'; quiting ! the file will kill the buffer." ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. (let ((last-nonmenu-event t) client-record) ;; Restore the current buffer afterward, but not using save-excursion, *************** *** 1363,1368 **** --- 1369,1379 ---- (run-hooks 'server-visit-hook) ;; hooks may be specific to current buffer: (run-hooks 'post-command-hook)) + (when readonly + ;; enable view mode and view-quit will mark the buffer as done + (view-mode +1) + (unless nowait + (setq view-exit-action 'server-buffer-done))) (unless nowait ;; When the buffer is killed, inform the clients. (add-hook 'kill-buffer-hook 'server-kill-buffer nil t)