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-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

* 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, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2008-09-05  3:55 UTC (permalink / raw)
  To: Anonymous Sender; +Cc: bug-gnu-emacs, 890

> 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)?


        Stefan







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

* 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-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
  1 sibling, 0 replies; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-06 12:53 UTC (permalink / raw)
  To: find lulu, 890

find lulu wrote:
>>>/ 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.

Is there anything here that is specific to Emacs+EmacsW32?






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  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)
                     ` (2 more replies)
  1 sibling, 3 replies; 14+ messages in thread
From: Stefan Monnier @ 2008-09-06 19:41 UTC (permalink / raw)
  To: find lulu; +Cc: bug-gnu-emacs, 890

>>> * 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?"

Indeed, it's part of the question ;-)
IIUC emacs.bash was written before emacsclient got its -a argument and
it should either be removed or changed to use emacsclient's -a argument.

But for that, we need someone (e.g. you) to test the replacement.


        Stefan






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  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:20   ` martin rudalics
  2008-09-07 22:01   ` find lulu
  2 siblings, 1 reply; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-06 20:11 UTC (permalink / raw)
  To: Stefan Monnier, 890; +Cc: find lulu

Stefan Monnier wrote:
>>>> * 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?"
> 
> Indeed, it's part of the question ;-)
> IIUC emacs.bash was written before emacsclient got its -a argument and
> it should either be removed or changed to use emacsclient's -a argument.
> 
> But for that, we need someone (e.g. you) to test the replacement.


Or, in the a bit longer perspective perhaps, emacsclient should be
enhanced to start Emacs itself when needed. (As you know there is code
for this available.)






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 20:11   ` Lennart Borgman (gmail)
@ 2008-09-06 20:33     ` Juanma Barranquero
  2008-09-06 21:46       ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 14+ messages in thread
From: Juanma Barranquero @ 2008-09-06 20:33 UTC (permalink / raw)
  To: Lennart Borgman (gmail), 890; +Cc: find lulu

On Sat, Sep 6, 2008 at 22:11, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:

> Or, in the a bit longer perspective perhaps, emacsclient should be
> enhanced to start Emacs itself when needed. (As you know there is code
> for this available.)

No, Lennart, as we've discussed a few times, there is no "code for
this available". There is a very different emacsclient (yours) with
that capability. If you were to take the time to send a patch against
the trunk, we'd be glad to review it.

 Juanma






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 19:41 ` Stefan Monnier
  2008-09-06 20:11   ` Lennart Borgman (gmail)
@ 2008-09-06 21:20   ` martin rudalics
  2008-09-07  4:03     ` find lulu
  2008-09-07 22:01   ` find lulu
  2 siblings, 1 reply; 14+ messages in thread
From: martin rudalics @ 2008-09-06 21:20 UTC (permalink / raw)
  To: Stefan Monnier, 890; +Cc: find lulu

 > But for that, we need someone (e.g. you) to test the replacement.

Since the original report is IMHO the most accurately written one to
ever appear on this list, we should maybe ask its author to provide
patches for the replacements he suggested ;-)

martin






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 20:33     ` Juanma Barranquero
@ 2008-09-06 21:46       ` Lennart Borgman (gmail)
  2008-09-06 22:06         ` Juanma Barranquero
  0 siblings, 1 reply; 14+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-06 21:46 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: find lulu, 890

Juanma Barranquero wrote:
> On Sat, Sep 6, 2008 at 22:11, Lennart Borgman (gmail)
> <lennart.borgman@gmail.com> wrote:
> 
>> Or, in the a bit longer perspective perhaps, emacsclient should be
>> enhanced to start Emacs itself when needed. (As you know there is code
>> for this available.)
> 
> No, Lennart, as we've discussed a few times, there is no "code for
> this available". There is a very different emacsclient (yours) with
> that capability. If you were to take the time to send a patch against
> the trunk, we'd be glad to review it.


Ok, 1-1 in excaggerations ;-)

The problem is not the code, the problem is the merging.

I have rearranged the code quite a bit to make it fit for starting Emacs
when it is not already running. That makes it hard to see what is
happening when we try to merge - and that is why you and I gave up last
time.

I suppose it might be my fault because I did not very clearly say what
is needed. Here is how I think it can be done:

- Before actually merging the code try to merge the primitives (ie the
function) used for giving messages and error handling. That will make it
much easier to merge later because it will be much less output from the
diff command. After this test that everything is working.

- Rearrange a bit in next step for the same reason. Now test again so we
did not do something stupid.

- Then actually do the merge of the code that might fail. Now we have a
much smaller diff to wade through if something unexpectedly goes wrong.

What do you say, Juanma?

And when can we do it?






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 21:46       ` Lennart Borgman (gmail)
@ 2008-09-06 22:06         ` Juanma Barranquero
  2011-03-03  6:45           ` Glenn Morris
  0 siblings, 1 reply; 14+ messages in thread
From: Juanma Barranquero @ 2008-09-06 22:06 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: find lulu, 890

On Sat, Sep 6, 2008 at 23:46, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:

> What do you say, Juanma?

No problem, as long as you do the patches...

> And when can we do it?

Start sending them at your convenience.

 Juanma






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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 21:20   ` martin rudalics
@ 2008-09-07  4:03     ` find lulu
  2008-09-07  9:37       ` martin rudalics
  0 siblings, 1 reply; 14+ messages in thread
From: find lulu @ 2008-09-07  4:03 UTC (permalink / raw)
  To: martin rudalics; +Cc: bug-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 188 bytes --]

If these are not moot, here are suggested patch files and ChangeLog entries
for `emacs/etc/emacs.bash' and `emacs/lisp/server.el' for the latest
revisions on the CVS branch EMACS_22_BASE.

[-- Attachment #1.2: Type: text/html, Size: 225 bytes --]

[-- Attachment #2: ChangeLog --]
[-- Type: application/octet-stream, Size: 148 bytes --]

2008-09-06  <tpeplt@gmail.com>

	* emacs.bash: Added a test for the server file created by EmacsW32
	to the conditional for invoking `emacsclient'.

[-- Attachment #3: emacs.bash.patch --]
[-- Type: application/octet-stream, Size: 833 bytes --]

*** emacs/etc/emacs.bash-1.5.2.2	Sat Sep  6 21:22:20 2008
--- emacs/etc/emacs.bash.new	Sat Sep  6 21:23:17 2008
***************
*** 46,52 ****
   if [ -n "${windowsys:+set}" ]; then
      # Do not just test if these files are sockets.  On some systems
      # ordinary files or fifos are used instead.  Just see if they exist.
!     if [ -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then
         emacsclient "$@"
         return $?
      else
--- 46,52 ----
   if [ -n "${windowsys:+set}" ]; then
      # Do not just test if these files are sockets.  On some systems
      # ordinary files or fifos are used instead.  Just see if they exist.
!     if [ -e "${HOME}/.emacs.d/server/server" -o -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then
         emacsclient "$@"
         return $?
      else

[-- Attachment #4: ChangeLog --]
[-- Type: application/octet-stream, Size: 387 bytes --]

2008-09-06  <tpeplt@gmail.com>

	* server.el (server-start): Moved the code that removes any
	leftover socket or authentication file before (and outside) the
	condition that checks to see whether the server should be left
	shut down.  This ensures that the server's socket or
	authentication file is also removed when Emacs is shut down,
	instead of only prior to restarting the server.

[-- Attachment #5: server.el.patch --]
[-- Type: application/octet-stream, Size: 1504 bytes --]

*** emacs/lisp/server.el-1.127.2.6	Sat Sep  6 22:09:51 2008
--- emacs/lisp/server.el.new	Sat Sep  6 22:19:59 2008
***************
*** 323,335 ****
      (let ((buffer (nth 1 (car server-clients))))
        (server-buffer-done buffer)))
    ;; Now any previous server is properly stopped.
!   (unless leave-dead
!     (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))
        (when server-process
          (server-log (message "Restarting server")))
        (letf (((default-file-modes) ?\700))
--- 323,335 ----
      (let ((buffer (nth 1 (car server-clients))))
        (server-buffer-done buffer)))
    ;; Now any previous server is properly stopped.
!   (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))
!     (unless leave-dead
        (when server-process
          (server-log (message "Restarting server")))
        (letf (((default-file-modes) ?\700))

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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-07  4:03     ` find lulu
@ 2008-09-07  9:37       ` martin rudalics
  0 siblings, 0 replies; 14+ messages in thread
From: martin rudalics @ 2008-09-07  9:37 UTC (permalink / raw)
  To: find lulu; +Cc: bug-gnu-emacs

> If these are not moot, here are suggested patch files and ChangeLog entries
> for `emacs/etc/emacs.bash' and `emacs/lisp/server.el' for the latest
> revisions on the CVS branch EMACS_22_BASE.

Emacs 22 is not going to change any more.  Can you provide patches and test
them for Emacs 23?

martin








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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 19:41 ` Stefan Monnier
  2008-09-06 20:11   ` Lennart Borgman (gmail)
  2008-09-06 21:20   ` martin rudalics
@ 2008-09-07 22:01   ` find lulu
  2 siblings, 0 replies; 14+ messages in thread
From: find lulu @ 2008-09-07 22:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: bug-gnu-emacs

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

I have installed the newly announced EmacsW32, version 22.3 and attempted to
start Emacs with the following command at the Cygwin `bash' prompt:

$ mv ~/.emacs ~/keep.emacs  # preserve init. file while testing

$ emacsclient --version
emacsclient 22.3

$ emacsclient --alternate-editor=emacs ~/.bashrc
emacsclient.exe: connect: No connection could be made because the target
machine actively refused it.

However, despite the error message, Emacs starts as expected.  Within Emacs,
I ran the command M-x server-start
to start the Emacs server.  A subsequent `emacsclient' command works as
expected:

$ emacsclient --alternate-editor=emacs ~/keep.emacs
Waiting for Emacs...

If the changes I suggested earlier for Emacs 22's `lisp/server.el' are made,
then the error message is not displayed after the initial invocation of
`emacsclient'.  The reason the error message is displayed is the same,
namely, that when Emacs is shutting down and calls `(server-start -1)', the
code in `server-start' does not remove the server file
~/.emacs.d/server/server.


On Sat, Sep 6, 2008 at 3:41 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:

> >>> * 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?"
>
> Indeed, it's part of the question ;-)
> IIUC emacs.bash was written before emacsclient got its -a argument and
> it should either be removed or changed to use emacsclient's -a argument.
>
> But for that, we need someone (e.g. you) to test the replacement.
>
>
>        Stefan
>

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

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

* bug#890: Problem using `etc/emacs.bash' with EmacsW32
  2008-09-06 22:06         ` Juanma Barranquero
@ 2011-03-03  6:45           ` Glenn Morris
  0 siblings, 0 replies; 14+ messages in thread
From: Glenn Morris @ 2011-03-03  6:45 UTC (permalink / raw)
  To: 890-done

Version: 24.1

etc/emacs.bash has been removed for 24.1.





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