all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#890: Problem using `etc/emacs.bash' with EmacsW32
@ 2008-09-05 15:39 find lulu
  2008-09-06 12:53 ` Lennart Borgman (gmail)
  2008-09-06 19:41 ` Stefan Monnier
  0 siblings, 2 replies; 14+ messages in thread
From: find lulu @ 2008-09-05 15:39 UTC (permalink / raw)
  To: bug-gnu-emacs

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

>>* I am attempting to use the shell script `emacs.bash' that is provided*
>
> Could you explain why you don't ust use emacsclient directly (together
> with its -a argument)?

Your question prompts the question "Why does `etc/emacs.bash' exist at all?"

The reason for `emacs.bash' to exist is to provide a single, consistent
command for editing a file from the bash shell prompt, namely, 'edit'.

It is certainly possible to use alternatives to avoid the problems described,
but if `etc/emacs.bash' is to be included in the Emacs distribution then it
should work for that distribution.

In brief, here are the two problems restated (for EmacsW32):

1. `etc/emacs.bash' does not check for the file `~/.emacs.d/server/server'
   that is created when `server-start' is invoked from EmacsW32.  As a result,
   `emacsclient' is not invoked by the shell function `edit' that is created
   when `etc/emacs.bash' is sourced.

2. When `server-start' (in `lisp/server.el') is invoked during the Emacs
   shutdown process, it does not remove the file `~/.emacs.d/server/server'
   that it created when it was initially invoked.  Consequently, additional
   calls to the shell function 'edit' do not work properly -- namely, `edit'
   should invoke `emacs' instead of `emacsclient' when there is no instance
   of the emacs's server running.

These problems should be fixed so that `edit' works for EmacsW32 as it does
for Emacs on other platforms.  Some possible fixes were suggested in the
original problem report.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread
* bug#890: Problem using `etc/emacs.bash' with EmacsW32
@ 2008-09-04 19:55 Anonymous Sender
  2008-09-05  3:55 ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Anonymous Sender @ 2008-09-04 19:55 UTC (permalink / raw)
  To: bug-gnu-emacs

In GNU Emacs 22.2.1 (i386-mingw-nt5.1.2600)
 of 2008-03-26 on RELEASE
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4)'

I am attempting to use the shell script `emacs.bash' that is provided
in the `etc' directory of the GNU Emacs distribution.  This script
defines the shell function named 'edit' to provide a single,
consistent command for starting Emacs and subsequently, for calling
Emacs via `emacsclient', if `server-start' has been invoked via either
the initialization file or M-x server-start.

After sourcing the script, the command 'edit [filename]' starts Emacs
as expected.  However, subsequent calls to `edit' do not result in
`emacsclient' being invoked.  Instead, new instances of `emacs' are
started.  The reason for this is that the script contains the
following test, which fails for EmacsW32:

  if [ -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then

Neither of these files is created by EmacsW32.  Instead, the file
${HOME}/.emacs.d/server/server is created, by default, when
`server-start' is invoked from EmacsW32.  I would like to suggest that
`etc/emacs.bash' be changed to include that server file in its test
for starting `emacsclient', that is, change the test, above, to:

  if [ -e "${HOME}/.emacs.d/server/server" -o -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then

With this change, the shell function `edit' then appropriately calls
`emacsclient' after Emacs has started its server.

A second problem occurs after Emacs has been stopped ("killed").  The
next time `edit' is called, the code in `etc/emacs.bash' calls
`emacsclient' even though Emacs and its server are not running.  The
reason for this appears to be that the function `server-start' in
`lisp/server.el' does not remove ${HOME}/.emacs.d/server/server when
it is called when Emacs is killed via C-x C-c (that is,
`save-buffers-kill-emacs').

Here is the sequence of calls:

- When `(server-start)' is invoked, the following code in
  `lisp/server.el' adds an anonymous function to `kill-emacs-hook':

  (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit.

- When emacs is exited via C-x C-c, the function
  `save-buffers-kill-emacs' is called.

- The function `save-buffers-kill-emacs' calls the function
  `kill-emacs', which, in turn, calls the list of functions in
  `kill-emacs-hook'.

- `server-mode' includes the form:

   (server-start (not server-mode))

- When the function `server-start' is called with its optional
  parameter `leave-dead' set to nil, the code in the following the
  condition in the form:

   (unless leave-dead ...)

  is not executed.  This includes the code to remove the server file
  that was created when `server-start' was originally called, namely,

  (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir))
         (server-file (expand-file-name server-name server-dir)))
    ;; Make sure there is a safe directory in which to place the socket.
    (server-ensure-safe-dir server-dir)
    ;; Remove any leftover socket or authentication file
    (ignore-errors (delete-file server-file))
    ...)) ; `let' and `unless'

A possible solution to this problem is to move the `(unless
leave-dead)' form inside the `(let* ...)' form after the form:

    (ignore-errors (delete-file server-file))

I have made this change in my copy of `lisp/server.el' and confirmed
that `edit' works correctly for EmacsW32, that is, it starts `emacs'
if there is no instance of `emacs' running, and starts `emacsclient'
if emacs's server is running.

; End of report








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

end of thread, other threads:[~2011-03-03  6:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-05 15:39 bug#890: Problem using `etc/emacs.bash' with EmacsW32 find lulu
2008-09-06 12:53 ` Lennart Borgman (gmail)
2008-09-06 19:41 ` Stefan Monnier
2008-09-06 20:11   ` Lennart Borgman (gmail)
2008-09-06 20:33     ` Juanma Barranquero
2008-09-06 21:46       ` Lennart Borgman (gmail)
2008-09-06 22:06         ` Juanma Barranquero
2011-03-03  6:45           ` Glenn Morris
2008-09-06 21:20   ` martin rudalics
2008-09-07  4:03     ` find lulu
2008-09-07  9:37       ` martin rudalics
2008-09-07 22:01   ` find lulu
  -- strict thread matches above, loose matches on Subject: below --
2008-09-04 19:55 Anonymous Sender
2008-09-05  3:55 ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.