bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Suggested enhancement: allow emacsclient to send arbitrary LISP express


From: tytso
Subject: Suggested enhancement: allow emacsclient to send arbitrary LISP expressions
Date: Thu, 02 Jan 2003 15:48:24 -0500

This patch allows the emacs client to pass in an arbitrary lisp
expression, which will be executed by the emacs server process.  

For example: emacsclient '(make-frame-on-display "localhost:12")'

The patch is fully backwards compatible with older versions of
emacsclient, since emacsclient always sends absolute pathnames to the
emacs server.  The leading open parenthesis is used to indicate that
string is a lisp expression which should be evalulated.

On the emacsclient side, currently we simply use a leading open
parenthesis to indicate that the argument is a LISP expression.  This
means that attempts to edit a file that begins with an open expression
will now be interpreted as a LISP expression.  In practice I don't
expect this to be a problem, although if this is a major concern, a
option such as --lisp could be added to emacsclient to inhibit adding
the absolute pathname to the argument, instead of always treating
arguments that begin with an open parenthesis as LISP expressions.

Note: If I were designing the emacsclient/emacsserver protocol all
over again from scratch, emacsclient would always pass s-expressions
which would be intepreted as lisp expressions by the emacs process.
This would eliminate the current kludgy, ad-hoc quoting that
emacsclient uses.

                                                - Ted


--- emacsclient.c       2003/01/02 19:33:41     1.2
+++ emacsclient.c       2003/01/02 19:34:43
@@ -326,7 +326,7 @@
          if (*p != 0)
            fprintf (out, "%s/", quote_file_name (cwd));
        }
-      else if (*argv[i] != '/')
+      else if (*argv[i] != '/' && *argv[i] != '(')
        fprintf (out, "%s/", quote_file_name (cwd));
 
       fprintf (out, "%s ", quote_file_name (argv[i]));
--- /home/tytso/em/server.el    2003-01-02 15:21:03.000000000 -0500
+++ /usr/share/emacs/20.7/lisp/server.el        1999-03-12 19:20:25.000000000 
-0500
@@ -213,8 +213,7 @@
          (coding-system (and default-enable-multibyte-characters
                              (or file-name-coding-system
                                  default-file-name-coding-system)))
-         client nowait 
-         (result "error in lisp expression")
+         client nowait
          (files nil)
          (lineno 1))
       ;; Remove this line from STRING.
@@ -226,24 +225,6 @@
              (setq request (substring request (match-end 0)))
              (setq client (list (substring request 0 (string-match " " 
request))))
              (setq request (substring request (match-end 0)))
-             (if (string-match "^(" request)
-                 (let ((q (read-from-string request))
-                       arg
-                       (pos 0))
-                   (setq arg (substring request 0 (cdr q)))
-                   (setq request (substring request (cdr q)))
-                   (while (string-match "&." arg pos)
-                     (setq pos (1+ (match-beginning 0)))
-                     (let ((nextchar (aref arg pos)))
-                       (cond ((= nextchar ?&)
-                              (setq arg (replace-match "&" t t arg)))
-                             ((= nextchar ?-)
-                              (setq arg (replace-match "-" t t arg)))
-                             (t
-                              (setq arg (replace-match " " t t arg))))))
-                   (unwind-protect
-                       (setq result (eval (car (read-from-string arg)))))
-                   ))
              (while (string-match "[^ ]+ " request)
                (let ((arg
                       (substring request (match-beginning 0) (1- (match-end 
0))))
@@ -275,20 +256,14 @@
                            (cons (list arg lineno)
                                  files))
                      (setq lineno 1)))))
-             (if files
-                 (progn 
-                   (server-visit-files files client nowait)
-                   ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
-                   (or nowait
-                       (setq server-clients (cons client server-clients)))
-                   (server-switch-buffer (nth 1 client))
-                   (run-hooks 'server-switch-hook)
-                   (message (substitute-command-keys
-                             "When done with a buffer, type \\[server-edit]")))
-               (let ((logmsg (format "Close: %s %s\n" (car client) 
-                                     (prin1-to-string result))))
-                 (send-string server-process logmsg)
-                 (server-log logmsg))))))))
+             (server-visit-files files client nowait)
+             ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
+             (or nowait
+                 (setq server-clients (cons client server-clients)))
+             (server-switch-buffer (nth 1 client))
+             (run-hooks 'server-switch-hook)
+             (message (substitute-command-keys
+                       "When done with a buffer, type \\[server-edit]")))))))
   ;; Save for later any partial line that remains.
   (setq server-previous-string string))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]