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

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

Re: 24.1.50 + lexical-binding + server.el + server-visit-hook = problem


From: Kevin Rodgers
Subject: Re: 24.1.50 + lexical-binding + server.el + server-visit-hook = problem
Date: Wed, 06 Jun 2012 21:42:52 -0600
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20

On 6/6/12 2:01 PM, Jim Diamond wrote:
On 2012-06-05 at 22:17 ADT, Stefan Monnier<monnier@iro.umontreal.ca>  wrote:
While using 23.4 (and some other older versions) I added a hook to
server-visit-hook.  My hook function uses the variable "dir", which is
meaningful at the point where server-visit-hook is called.

What does your hook do and how does it use this `dir'?

At the risk of boring you with an overly long story...

For a long, long time I have been using a package called saveconf.el.
(I have modified it over the years, but the first two lines are
as follows:
;;; Save Emacs buffer and window configuration between editing sessions.
;;; Copyright (C) 1987, 1988 Kyle E. Jones
)

This package, originally designed for use NOT in server/daemon mode,
saves the information about what files you were working on when you
exited emacs.  Unlike (my possibly incorrect) understanding of
desktop.el, it saves this information on a per-directory basis, so
that if you were editing /a/b/c/xyz.c in directory D last week and now
cd into that directory, a script I wrote will start up emacsclient
with the appropriate file (/a/b/c/xyz.c) at the appropriate line.
(Or, if I start a new instance of emacs, the information will be read
automagically and the file I was previously editing will reappear at
the correct line.)

To clarify, in directory D a file is saved which has /a/b/c/xyz.c and
the line number of (point) when I finished editing the file.

I modified (possibly in a bad way) saveconf.el for the server/client
scenario by adding a function to server-visit-hook.  This function
saves the file's directory in a buffer-local variable when the file is
initially visited.  This information is used when I finish editing the
buffer, so that it knows in which directory to store my information
file.

Here is my code which I believe is relevant to your question:

(require 'server)
(defvar emacsclient-dir-for-this-buffer nil
     "Name of the directory emacsclient was called from for this buffer.")
(make-variable-buffer-local 'emacsclient-dir-for-this-buffer)
(defun saveconf-server-save-emacsclient-dir ()
     "Save the directory from which emacsclient was called.
     This is called from a place in server.el (server-visit-files)
     where the variable 'dir' is equal to the directory emacsclient
     was called from."
     (setq emacsclient-dir-for-this-buffer dir)
)
(add-hook 'server-visit-hook 'saveconf-server-save-emacsclient-dir)


Does that answer your question?
And, if so, do you have a suggestion on the right way to get this
information I want?

Ideally, server.el would define a global dynamically-scoped variable
`server-default-directory' that users could reliably reference to get
the value of the -dir DIRNAME emacsclient option (instead of defining
the internal lexically scoped `dir').

But until then, I think you could fake it by calling emacsclient from
a shell with -eval "(setq server-default-directory \"$PWD\")"

--
Kevin Rodgers
Denver, Colorado, USA




reply via email to

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