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

* Re: patch for emacsclient to support GNU_NODE
  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
  0 siblings, 1 reply; 8+ messages in thread
From: tomas @ 2010-02-26 14:01 UTC (permalink / raw)
  To: Hugh Holbrook; +Cc: emacs-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Feb 25, 2010 at 10:58:36PM -0800, Hugh Holbrook wrote:
> I'd like to offer the attached patch to emacs.  I have been
> using this for a while now and find it useful.

Excuse my ignorance, but where could I look up what this is for?

Browsing through the comments in the patch gives me a very nebulous idea
about what this does, but my imagination is just too narrow to fathom
what for I'd like to use it. OTOH it does sound useful, thus my genuine
curiousity :-)

Thanks for any hints

- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFLh9RJBcgs9XrR2kYRAkl9AJ9VxCHzrSaneqNfECQYkgGb+R13lACdHetE
GdTjEZMx6KSZbHTBpMDLTPE=
=YHZN
-----END PGP SIGNATURE-----




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

* Re: patch for emacsclient to support GNU_NODE
  2010-02-26 14:01 ` tomas
@ 2010-02-26 14:26   ` Davis Herring
  2010-02-26 22:37     ` Hugh Holbrook
  0 siblings, 1 reply; 8+ messages in thread
From: Davis Herring @ 2010-02-26 14:26 UTC (permalink / raw)
  To: tomas; +Cc: Hugh Holbrook, emacs-devel

> Excuse my ignorance, but where could I look up what this is for?

It just lets emacsclient send a directory name to Emacs that (on Emacs'
machine) provides remote access to emacsclient's machine, so that Emacs
can open files that emacsclient refers to it that are not reachable with
just the literal filename given.  (Apparently it has to be to the root of
that machine, since it's just prepended?)

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




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

* Re: patch for emacsclient to support GNU_NODE
  2010-02-26 14:26   ` Davis Herring
@ 2010-02-26 22:37     ` Hugh Holbrook
  2010-02-26 22:57       ` Davis Herring
                         ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hugh Holbrook @ 2010-02-26 22:37 UTC (permalink / raw)
  To: herring; +Cc: tomas, emacs-devel

On Fri, Feb 26, 2010 at 6:26 AM, Davis Herring <herring@lanl.gov> wrote:
>> Excuse my ignorance, but where could I look up what this is for?
>
> It just lets emacsclient send a directory name to Emacs that (on Emacs'
> machine) provides remote access to emacsclient's machine, so that Emacs
> can open files that emacsclient refers to it that are not reachable with
> just the literal filename given.  (Apparently it has to be to the root of
> that machine, since it's just prepended?)

Yes, precisely.  So for example, a file that is called /tmp/foobar by
the emacsclient process might be reachable using NFS as
/net/myhost/tmp/foobar on the host where emacs is running.  You would
set GNU_NODE to /net/myhost in this case.

In my use case, I am invoking emacsclient from within a chrooted shell
and using TCP to connect to an emacs process that is running on the
same host, but outside the chroot.  Every file in the chroot is
nameable in the root file system, but with a different path prefix.

GNU_NODE_EXCLUDE is useful if some directory is mounted with the same
path on both the client and server machine.  In my case, the home
directory is special-cased and appears as /home/username to both the
emacs and emacsclient process.

Hope that helps to explain why this is useful.

Thanks,

-Hugh

> Davis
>




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

* Re: patch for emacsclient to support GNU_NODE
  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
  2 siblings, 0 replies; 8+ messages in thread
From: Davis Herring @ 2010-02-26 22:57 UTC (permalink / raw)
  To: Hugh Holbrook; +Cc: tomas, emacs-devel

> Yes, precisely.  So for example, a file that is called /tmp/foobar by
> the emacsclient process might be reachable using NFS as
> /net/myhost/tmp/foobar on the host where emacs is running.  You would
> set GNU_NODE to /net/myhost in this case.

In my experience it's more common for individual directories to be
exported, and then (often) mounted at a mount point that doesn't contain
the name of the exported directory as a suffix.  Your code could handle
just /home being exported and mounted as /net/fileserver/home, but
wouldn't help if it were mounted as /nethome/fileserver.

Why not (perhaps in addition to the GNU_NODE support, which I understand
is for compatibility) allow some setting (be it an environment variable or
otherwise) that contains pairs of directory names, so that you could set

EMACSCLIENT_REMAP=/home:/nethome/fileserver:/var/tmp:/scratch

and support arbitrary mappings?

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




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

* Re: patch for emacsclient to support GNU_NODE
  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
  2 siblings, 0 replies; 8+ messages in thread
From: tomas @ 2010-02-27  5:45 UTC (permalink / raw)
  To: Hugh Holbrook; +Cc: tomas, emacs-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Feb 26, 2010 at 02:37:14PM -0800, Hugh Holbrook wrote:
> On Fri, Feb 26, 2010 at 6:26 AM, Davis Herring <herring@lanl.gov> wrote:
> >> Excuse my ignorance, but where could I look up what this is for?
> >
> > It just lets emacsclient send a directory name to Emacs that (on Emacs'
> > machine) provides remote access to emacsclient's machine, so that Emacs
> > can open files that emacsclient refers to it that are not reachable with
> > just the literal filename given.  (Apparently it has to be to the root of
> > that machine, since it's just prepended?)
> 
> Yes, precisely.  So for example, a file that is called /tmp/foobar by
> the emacsclient process might be reachable using NFS as
> /net/myhost/tmp/foobar on the host where emacs is running.  You would
> set GNU_NODE to /net/myhost in this case.

Thanks, David, Hugh. I'm now enlightened :-)

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFLiLFhBcgs9XrR2kYRAuSfAJ4qyU5GvcTspuhBco6yQ/o8V1EpYQCcCy0H
wcPh3RpNGSNGLt8d4ri5+nc=
=YCEV
-----END PGP SIGNATURE-----




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

* Re: patch for emacsclient to support GNU_NODE
  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
  2 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2010-02-27 14:29 UTC (permalink / raw)
  To: Hugh Holbrook; +Cc: tomas, emacs-devel

> Yes, precisely.  So for example, a file that is called /tmp/foobar by
> the emacsclient process might be reachable using NFS as
> /net/myhost/tmp/foobar on the host where emacs is running.  You would
> set GNU_NODE to /net/myhost in this case.

> In my use case, I am invoking emacsclient from within a chrooted shell
> and using TCP to connect to an emacs process that is running on the
> same host, but outside the chroot.  Every file in the chroot is
> nameable in the root file system, but with a different path prefix.

> GNU_NODE_EXCLUDE is useful if some directory is mounted with the same
> path on both the client and server machine.  In my case, the home
> directory is special-cased and appears as /home/username to both the
> emacs and emacsclient process.

Could you point to some origin for this mechanism?
Googling only seems to point to this current thread and to some
gnuclient stuff.  Is gnuclient the only other program using such
a convention?


        Stefan




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

* Re: patch for emacsclient to support GNU_NODE
  2010-02-27 14:29       ` Stefan Monnier
@ 2010-02-28  4:37         ` Hugh Holbrook
  0 siblings, 0 replies; 8+ messages in thread
From: Hugh Holbrook @ 2010-02-28  4:37 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: tomas, emacs-devel

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

On Sat, Feb 27, 2010 at 6:29 AM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:

> > GNU_NODE_EXCLUDE is useful if some directory is mounted with the same...
>
> Could you point to some origin for this mechanism?
> Googling only seems to point to this current thread and to some
> gnuclient stuff.


I was not aware of any other documentation than this, but searching google
groups turned up this link:

http://groups.google.com/group/gnu.emacs/browse_thread/thread/dcb0343a012b69dc/86931742d045b117?q=GNU_NODE#86931742d045b117

to a posting from 1989 that is, I believe, the origin of the implementation
in xemacs.

My understanding is that gnuclient uses four environment variables to
control the way that it connects to the server:

GNU_PORT and GNU_HOST to identify the location of the server
GNU_SECURE for authorization
GNU_NODE (as described in this thread).

As you probably know, emacsclient is different in that it uses a single file
in .emacs.d/server to identify the server's location, and for authorization,
I believe.

On my machine this file looks like this:

127.0.0.1:41055 15289
R`HIRQ;aQxEG.U7.u.VExqpQLga@4kL4h_xH|'n1",)SBf:1<Cu('ad1kIi1=yqZ


I considered using a more descriptive name than GNU_NODE
(EMACSCLIENT_PREFIX?) but ended up with GNU_NODE just for compatibility,
although given all the other differences the compatibility argument for
doing things this way is not very strong.

Is gnuclient the only other program using such
> a convention?
>

I think so.  I'm not aware of any other program that uses GNU_NODE in this
(or any other) way.  The idea and the environment variable name were
entirely inspired by gnuclient in my case.  GNU_NODE_EXCLUDE is, to my
knowledge, a new extension.

-Hugh


>        Stefan
>

[-- Attachment #2: Type: text/html, Size: 3081 bytes --]

^ 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).