unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* patch for emacsclient to support GNU_NODE
@ 2010-02-26  6:58 Hugh Holbrook
  2010-02-26 14:01 ` tomas
  0 siblings, 1 reply; 8+ messages in thread
From: Hugh Holbrook @ 2010-02-26  6:58 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

I'd like to offer the attached patch to emacs.  I have been
using this for a while now and find it useful.

The patch adds support for handling the GNU_NODE environment
variable in emacsclient, and documentation of it.  When TCP
connections are used, any local filename sent to the server is
absolutified and prefixed with the value of GNU_NODE, if set,
before sending. The GNU_NODE_EXCLUDE environment variable is a
PATH-style (colon-separated) list of directories to exclude
from GNU_NODE processing, which is useful if your home directory
is mounted at the same place locally and on the server.

This feature is inspired by similar support in gnuclient from
xemacs.  GNU_NODE_EXCLUDE is not present in gnuclient, to my
knowledge.  I preserved the name GNU_NODE to maintain
compatibility.

The patch attempts to support GNU_NODE when built for windows,
but I will confess to not having tested this on windows.

Thanks,

-Hugh Holbrook

[-- Attachment #2: emacs-gnu-node-patch --]
[-- Type: application/octet-stream, Size: 6373 bytes --]

2010-02-25  Hugh Holbrook  <holbrook@aristanetworks.com>

	* misc.texi (emacsclient Options): Add GNU_NODE and GNU_NODE_EXCLUDE.

diff -rcp emacs-vanilla/emacs-23.1/doc/emacs/misc.texi emacs-23.1/doc/emacs/misc.texi
*** emacs-vanilla/emacs-23.1/doc/emacs/misc.texi	2009-07-15 07:13:08.000000000 -0700
--- emacs-23.1/doc/emacs/misc.texi	2010-02-24 23:25:32.000000000 -0800
*************** runs, and (ii) provide @command{emacscli
*** 1647,1652 ****
--- 1647,1660 ----
  (One convenient way to do the latter is to put the server file on a
  networked file system such as NFS.)
  
+ The @env{GNU_NODE} environment variable may be useful in conjunction
+ with TCP connections.  If set, its value is treated as a pathname
+ prefix that is prepended to the absolutized pathname of the local file
+ before sending to the server.  @env{GNU_NODE_EXCLUDE} is a list of
+ filesystem prefixes that should not be prefixed with @env{GNU_NODE}.
+ This is useful if there are directories that are mounted at the same
+ path on the server as locally.
+ 
  @item -n
  @itemx --no-wait
  Let @command{emacsclient} exit immediately, instead of waiting until



2010-02-25  Hugh Holbrook  <holbrook@aristanetworks.com>

	* emacsclient.1: Document GNU_NODE and GNU_NODE_EXCLUDE.

diff -rcp emacs-vanilla/emacs-23.1/doc/man/emacsclient.1 emacs-23.1/doc/man/emacsclient.1
*** emacs-vanilla/emacs-23.1/doc/man/emacsclient.1	2008-12-12 20:14:26.000000000 -0800
--- emacs-23.1/doc/man/emacsclient.1	2010-02-24 23:18:55.000000000 -0800
*************** use socket named FILENAME for communicat
*** 69,74 ****
--- 69,78 ----
  .B \-f, \-\-server-file=FILENAME
  use TCP configuration file FILENAME for communication.
  This can also be specified via the `EMACS_SERVER_FILE' environment variable.
+ The `GNU_NODE` environment variable, if set, is prefixed to any filename
+ sent to the server.  The `GNU_NODE_EXCLUDE` environment variable is a
+ set of directory names to exclude from `GNU_NODE` prefixing.  It uses
+ the same format as `PATH`.
  .TP
  .B \-a, \-\-alternate-editor=EDITOR
  if the Emacs server is not running, run the specified editor instead.




2010-02-25  Hugh Holbrook  <holbrook@aristanetworks.com>

	* emacsclient.c (main): Add GNU_NODE and GNU_NODE_EXCLUDE.
	(get_token) New function.

diff -rcp emacs-vanilla/emacs-23.1/lib-src/emacsclient.c emacs-23.1/lib-src/emacsclient.c
*** emacs-vanilla/emacs-23.1/lib-src/emacsclient.c	2009-06-20 21:37:34.000000000 -0700
--- emacs-23.1/lib-src/emacsclient.c	2010-02-25 22:18:24.000000000 -0800
*************** xstrdup (const char *s)
*** 206,213 ****
    return result;
  }
  
! /* From sysdep.c */
! #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
  
  /* From lisp.h */
  #ifndef DIRECTORY_SEP
--- 206,217 ----
    return result;
  }
  
! /* From ebrowse.c */
! #if defined(__MSDOS__) || defined(WINDOWSNT)
! #define PATH_LIST_SEPARATOR ';'
! #else
! #define PATH_LIST_SEPARATOR ':'
! #endif
  
  /* From lisp.h */
  #ifndef DIRECTORY_SEP
*************** xstrdup (const char *s)
*** 227,232 ****
--- 231,238 ----
  #define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
  #endif
  
+ /* From sysdep.c */
+ #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
  
  /* Return the current working directory.  Returns NULL on errors.
     Any other returned value must be freed with free.  This is used
*************** start_daemon_and_retry_set_socket (void)
*** 1488,1500 ****
  #endif /* WINDOWSNT */
  }
  
  int
  main (argc, argv)
       int argc;
       char **argv;
  {
    int i, rl, needlf = 0;
!   char *cwd, *str;
    char string[BUFSIZ+1];
    int null_socket_name, null_server_file, start_daemon_if_needed;
  
--- 1494,1528 ----
  #endif /* WINDOWSNT */
  }
  
+ /* Get the first token from a null-terminated string s, where the
+    tokens are delimited by the separator char.  The separator is
+    replaced by 0 in place, and rest is updated to point at the next
+    character after the separator.  rest is set to 0 when all tokens
+    have been returned. */
+ char *
+ get_token (char * s, char ** rest, char separator)
+ {
+   char * tail;
+   if (!s)
+     return 0;
+   
+   tail = strchr (s, separator);
+   if (tail)
+     {
+       *tail=0;
+       tail++;
+     }
+   *rest = tail;
+   return s;
+ }
+ 
  int
  main (argc, argv)
       int argc;
       char **argv;
  {
    int i, rl, needlf = 0;
!   char *cwd, *str, *gnu_node;
    char string[BUFSIZ+1];
    int null_socket_name, null_server_file, start_daemon_if_needed;
  
*************** main (argc, argv)
*** 1656,1662 ****
--- 1684,1743 ----
  		free (filename);
  	    }
  #endif
+ 	  if (gnu_node = egetenv ("GNU_NODE"))
+ 	    {
+ 	      int gnu_node_len = strlen (gnu_node);
+ 	      int cwd_len = strlen (cwd);
+ 	      int old_len = strlen (argv[i]);
+ 	      char *filename = (char *) xmalloc (gnu_node_len + cwd_len + old_len + 3);
+ 	      char *local_filename = (char *) xmalloc (cwd_len + old_len + 1);
+ 	      int absolute = file_name_absolute_p (argv[i]);
+ 	      int no_prefix = 0;
+ 
+ 	      if (!absolute)
+ 		{
+ 		  strcpy (local_filename, cwd);
+ 		  local_filename[cwd_len] = DIRECTORY_SEP;
+ 		  strcpy (local_filename + cwd_len + 1, argv[i]);
+ 		}
+ 	      else
+ 		local_filename = argv[i];
  
+ 	      /* GNU_NODE_EXCLUDE is a colon-separated set of prefixes to
+ 		 exclude from GNU_NODE prefixing.  Any filename
+ 		 starting with one of the elements of the GNU_NODE_EXCLUDE
+ 		 list will not be skipped. */
+ 	      if (egetenv ("GNU_NODE_EXCLUDE"))
+ 		{
+ 		  char *str = xstrdup (egetenv ("GNU_NODE_EXCLUDE"));
+ 		  char *rest;
+ 		  while (str = get_token (str, &rest, PATH_LIST_SEPARATOR))
+ 		    {
+ 		      if (strprefix (str, local_filename))
+ 			{
+ 			  char end = local_filename[strlen(str)];
+ 			  if (IS_DIRECTORY_SEP(end) || end == '\0')
+ 			    {
+ 			      no_prefix = 1;
+ 			      break;
+ 			    }
+ 			}
+                       str = rest;
+ 		    }
+ 		}
+ 
+ 	      if (!no_prefix)
+ 		{
+ 		  strcpy (filename, gnu_node);
+ 		  strcpy (filename + gnu_node_len, local_filename);
+ 		}
+ 	      else
+ 		{
+ 		  filename = local_filename;
+ 		}
+ 	      argv[i] = filename;
+ 	    }
+ 	  
            send_to_emacs (emacs_socket, "-file ");
            quote_argument (emacs_socket, argv[i]);
            send_to_emacs (emacs_socket, " ");

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-02-28  4:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-26  6:58 patch for emacsclient to support GNU_NODE Hugh Holbrook
2010-02-26 14:01 ` tomas
2010-02-26 14:26   ` Davis Herring
2010-02-26 22:37     ` Hugh Holbrook
2010-02-26 22:57       ` Davis Herring
2010-02-27  5:45       ` tomas
2010-02-27 14:29       ` Stefan Monnier
2010-02-28  4:37         ` Hugh Holbrook

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).