From 0191e222e375db31e08ef55f4eddc9e01e8d1f80 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sat, 29 May 2010 19:50:47 -0400 Subject: [PATCH] Add --parent-id argument to emacsclient. * lib-src/emacsclient.c (longopts, decode_options, print_help_and_exit): New arg `-parent-id'. (main): Send parent-id to Emacs. * lisp/server.el (server-process-filter): Receive parent-id argument from emacsclient. (server-create-window-system-frame): New arg. Pass parent-id as frame parameter. --- etc/NEWS | 4 ++++ lib-src/ChangeLog | 6 ++++++ lib-src/emacsclient.c | 19 ++++++++++++++++++- lisp/ChangeLog | 7 +++++++ lisp/server.el | 38 ++++++++++++++++++++++++-------------- 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index eece35bb6f0..62fe1ce1a86 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -43,6 +43,10 @@ You can disable this by using --without-selinux. * Changes in Emacs 24.1 +** New emacsclient argument --parent-id ID can be used to open a +client frame in parent X window ID, via XEmbed. This works like the +--parent-id argument to Emacs. + ** Completion can cycle, depending on completion-cycle-threshold. ** auto-mode-case-fold is now enabled by default. diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index ac1641a552e..d23fe3ff6c2 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,9 @@ +2010-05-29 Chong Yidong + + * emacsclient.c (longopts, decode_options, print_help_and_exit): + New arg `-parent-id'. + (main): Send parent-id to Emacs. + 2010-05-27 Glenn Morris * Makefile.in (distclean): No more Makefile.c. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 1e7ec7d9678..3172ebb8cd1 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -138,6 +138,9 @@ int current_frame = 1; /* The display on which Emacs should work. --display. */ char *display = NULL; +/* The parent window ID, if we are opening a frame via XEmbed. */ +char *parent_id = NULL; + /* Nonzero means open a new Emacs frame on the current terminal. */ int tty = 0; @@ -173,6 +176,7 @@ struct option longopts[] = #ifndef WINDOWSNT { "display", required_argument, NULL, 'd' }, #endif + { "parent-id", required_argument, NULL, 'p' }, { 0, 0, 0, 0 } }; @@ -583,6 +587,11 @@ decode_options (argc, argv) current_frame = 0; break; + case 'p': + parent_id = optarg; + current_frame = 0; + break; + case 'H': print_help_and_exit (); break; @@ -656,7 +665,8 @@ The following OPTIONS are accepted:\n\ -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ -n, --no-wait Don't wait for the server to return\n\ -d DISPLAY, --display=DISPLAY\n\ - Visit the file in the given display\n" + Visit the file in the given display\n\ +--parent-id=ID Open in parent window ID, via XEmbed\n" #ifndef NO_SOCKETS_IN_FILE_SYSTEM "-s SOCKET, --socket-name=SOCKET\n\ Set filename of the UNIX socket for communication\n" @@ -1620,6 +1630,13 @@ main (argc, argv) send_to_emacs (emacs_socket, " "); } + if (parent_id) + { + send_to_emacs (emacs_socket, "-parent-id "); + quote_argument (emacs_socket, parent_id); + send_to_emacs (emacs_socket, " "); + } + /* If using the current frame, send tty information to Emacs anyway. In daemon mode, Emacs may need to occupy this tty if no other frame is available. */ diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ee97e4f6af1..edde627ac20 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2010-05-29 Chong Yidong + + * server.el (server-process-filter): Receive parent-id argument + from emacsclient. + (server-create-window-system-frame): New arg. Pass parent-id as + frame parameter. + 2010-05-29 Chong Yidong * ansi-color.el: Delete unused escape sequences (Bug#6085). diff --git a/lisp/server.el b/lisp/server.el index fd2026c4ab8..1ac2fb5b361 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -711,7 +711,7 @@ Server mode runs a process that accepts commands from the (number-to-string (emacs-pid)) "\n")) frame)) -(defun server-create-window-system-frame (display nowait proc) +(defun server-create-window-system-frame (display nowait proc parent-id) (add-to-list 'frame-inherited-parameters 'client) (if (not (fboundp 'make-frame-on-display)) (progn @@ -727,12 +727,14 @@ Server mode runs a process that accepts commands from the (let* ((params `((client . ,(if nowait 'nowait proc)) ;; This is a leftover, see above. (environment . ,(process-get proc 'env)))) - (frame (make-frame-on-display - (or display - (frame-parameter nil 'display) - (getenv "DISPLAY") - (error "Please specify display")) - params))) + (display (or display + (frame-parameter nil 'display) + (getenv "DISPLAY") + (error "Please specify display"))) + frame) + (if parent-id + (push (cons 'parent-id (string-to-number parent-id)) params)) + (setq frame (make-frame-on-display display params)) (server-log (format "%s created" frame) proc) (select-frame frame) (process-put proc 'frame frame) @@ -900,15 +902,16 @@ The following commands are accepted by the client: (coding-system (and (default-value 'enable-multibyte-characters) (or file-name-coding-system default-file-name-coding-system))) - nowait ; t if emacsclient does not want to wait for us. - frame ; The frame that was opened for the client (if any). - display ; Open the frame on this display. - dontkill ; t if the client should not be killed. + nowait ; t if emacsclient does not want to wait for us. + frame ; Frame opened for the client (if any). + display ; Open frame on this display. + parent-id ; Window ID for XEmbed + dontkill ; t if client should not be killed. commands dir use-current-frame - tty-name ;nil, `window-system', or the tty name. - tty-type ;string. + tty-name ; nil, `window-system', or the tty name. + tty-type ; string. files filepos command-line-args-left @@ -935,6 +938,12 @@ The following commands are accepted by the client: (setq display (pop command-line-args-left)) (if (zerop (length display)) (setq display nil))) + ;; -parent-id ID: + ;; Open X frame within window ID, via XEmbed. + ((and (equal "-parent-id" arg) command-line-args-left) + (setq parent-id (pop command-line-args-left)) + (if (zerop (length parent-id)) (setq parent-id nil))) + ;; -window-system: Open a new X frame. ((equal "-window-system" arg) (setq dontkill t) @@ -1039,7 +1048,8 @@ The following commands are accepted by the client: (setq tty-name nil tty-type nil) (if display (server-select-display display))) ((eq tty-name 'window-system) - (server-create-window-system-frame display nowait proc)) + (server-create-window-system-frame display nowait proc + parent-id)) ;; When resuming on a tty, tty-name is nil. (tty-name (server-create-tty-frame tty-name tty-type proc)))) -- 2.39.2