From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: 24.1.50 + lexical-binding + server.el + server-visit-hook = problem Date: Wed, 06 Jun 2012 21:42:52 -0600 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1339040624 25172 80.91.229.3 (7 Jun 2012 03:43:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2012 03:43:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 07 05:43:43 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ScTdM-0000t1-Ea for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jun 2012 05:43:40 +0200 Original-Received: from localhost ([::1]:46137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScTdM-00056q-9v for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jun 2012 23:43:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScTcB-0001b9-7a for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 23:42:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ScTc9-000203-4D for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 23:42:26 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:55243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScTc8-0001zv-Pm for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 23:42:25 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ScTc2-0006Dx-ES for help-gnu-emacs@gnu.org; Thu, 07 Jun 2012 05:42:18 +0200 Original-Received: from c-71-237-25-24.hsd1.co.comcast.net ([71.237.25.24]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 07 Jun 2012 05:42:18 +0200 Original-Received: from kevin.d.rodgers by c-71-237-25-24.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 07 Jun 2012 05:42:18 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 69 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-25-24.hsd1.co.comcast.net 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 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85141 Archived-At: On 6/6/12 2:01 PM, Jim Diamond wrote: > On 2012-06-05 at 22:17 ADT, Stefan Monnier 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