From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: michael@mauger.com Newsgroups: gmane.emacs.devel Subject: Proposal: emacsclient --readonly Date: Wed, 13 Mar 2013 22:23:57 -0400 Message-ID: <87y5dqafcy.fsf@michael-laptop.hsd1.ma.comcast.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1363227849 5222 80.91.229.3 (14 Mar 2013 02:24:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Mar 2013 02:24:09 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 14 03:24:34 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UFxqL-0002OJ-5M for ged-emacs-devel@m.gmane.org; Thu, 14 Mar 2013 03:24:33 +0100 Original-Received: from localhost ([::1]:60047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFxpy-00010S-LF for ged-emacs-devel@m.gmane.org; Wed, 13 Mar 2013 22:24:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFxpq-000101-NS for emacs-devel@gnu.org; Wed, 13 Mar 2013 22:24:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFxpn-0004SF-Ie for emacs-devel@gnu.org; Wed, 13 Mar 2013 22:24:02 -0400 Original-Received: from nm37.bullet.mail.bf1.yahoo.com ([72.30.239.57]:37521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFxpn-0004S6-Ab for emacs-devel@gnu.org; Wed, 13 Mar 2013 22:23:59 -0400 Original-Received: from [98.139.212.145] by nm37.bullet.mail.bf1.yahoo.com with NNFMP; 14 Mar 2013 02:23:58 -0000 Original-Received: from [76.13.13.43] by tm2.bullet.mail.bf1.yahoo.com with NNFMP; 14 Mar 2013 02:23:58 -0000 Original-Received: from [127.0.0.1] by smtp104.prem.mail.ac4.yahoo.com with NNFMP; 14 Mar 2013 02:23:57 -0000 X-Yahoo-Newman-Id: 949475.94956.bm@smtp104.prem.mail.ac4.yahoo.com Original-Received: from michael-laptop.hsd1.ma.comcast.net (michael@98.216.52.54 with plain) by smtp104.prem.mail.ac4.yahoo.com with SMTP; 13 Mar 2013 19:23:57 -0700 PDT X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: HtQ1p8AVM1lX3rp_7pGAaKOqn06yHbEBntfaKh_PMheQsMK vi_WOr5BoBoV3UoxCLESIBMjjTw1OFtc2c4fglNFqNHbasNKCGn9v4v9hDeV 2ctTHhyODU7zCMR_pzKH.8gj0B30SBbMfurToTDeZkE7WtWyartwOwxncMnn hDHrJhgK59R4UcI9ewnwkWUsbV02sLAR5eWxqughbFTlCkkQCp.6lJns9zpT pw5McvYtpg5fcfgSwNSx.RQlj0vLMqkSc086KMi.Vi7qGessgyzhQO2pNJHO _7fHDXchEbPMbhjUXhKN8c0CO4Qc_yJoo4FXAH8_pgNtwbIVZRmQZ9pXwJR5 N_COohFUh4OC697uhtWFMGfeewa1pAc2vxe8kSnSB5HlPhzD8hnmQlX9vZFf 7PO4DOvwxG2SB8LFZMZnkmL61RpIUSL5NMRLcryrrff7VScyfPv0WYldWeDf XTeFnlSZplH7BMg-- X-Yahoo-SMTP: i_bv0HaswBBqrACeSLu_1E5b X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 72.30.239.57 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:157829 Archived-At: --=-=-= Content-Type: text/plain As distraction to our toddler temper-tantrum, I'd like to propose a new feature for emacsclient. I use emacsclient to open files frequently and I generally immediately do M-x view-mode once the frame pops up. I'd like to be able to open the file directly in view-mode when I invoke emacsclient. I'd be interested in any suggestions people have on how to accomplish this using emacsclient currently. In the absence of any ideas, I'd like to propose the folowing patch which adds a `--readonly,-r' option to emacsclient (and server.el) (I had originally called it --view-mode,-v but getopt_long_only complained that it was ambiguous if abbreviated.) I'm eager to hear any suggestions people might have to do this without changing emacsclient. Or maybe this is a reason to add a more generic feature to emacsclient to enable/disable modes after a file is opened. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=client-view.diff Content-Description: emacsclient --readonly feature *** 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) --=-=-= Content-Type: text/plain -- Michael R. Mauger - FSF Member #4247 - Emacs sql.el Maintainer --=-=-=--