zsh-workers
 help / color / mirror / code / Atom feed
* edit-command-line problem with emacsclient
@ 2015-09-20 11:46 Peter Vasil
  2015-09-20 15:32 ` Bart Schaefer
  2015-09-21 21:16 ` Daniel Shahaf
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Vasil @ 2015-09-20 11:46 UTC (permalink / raw)
  To: zsh-workers

Hi list,

Commit 35ffe36318955d03fca3df0d34a0997970cfc6a3 introduced the change,
that when calling edit-command-line, the curser is put to the right offset.

This is implemented for vim and emacs, however if I set my EDITOR or
VISUAL to emacsclient, the *emacs* condition gets called which does not
work for emacsclient. The arguments specidied for emacs work only for
Emacs but not for emacsclient.

It would be great to change the condition *emacs* that it does not match
emacsclient or add another condition for emacsclient with appropriate
arguments.

Thanks and bests,
Peter


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

* Re: edit-command-line problem with emacsclient
  2015-09-20 11:46 edit-command-line problem with emacsclient Peter Vasil
@ 2015-09-20 15:32 ` Bart Schaefer
       [not found]   ` <55FF3CE5.9070604@petervasil.net>
  2015-09-21 21:16 ` Daniel Shahaf
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2015-09-20 15:32 UTC (permalink / raw)
  To: Peter Vasil, zsh-workers

On Sep 20,  1:46pm, Peter Vasil wrote:
}
} This is implemented for vim and emacs, however if I set my EDITOR or
} VISUAL to emacsclient, the *emacs* condition gets called which does not
} work for emacsclient. The arguments specidied for emacs work only for
} Emacs but not for emacsclient.

So as I read this, for emacsclient the -eval option is mutually exclusive
with opening a file.

It's been a long time since I used emacsclient.  Does this work?


diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 2c7f34b..bdd7b0b 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -17,7 +17,7 @@
   local editor=${${VISUAL:-${EDITOR:-vi}}}
   case $editor in 
     (*vim*) ${=editor} -c "normal! ${byteoffset}go" -- $1;;
-    (*emacs*) ${=editor} $1 -eval "(goto-char ${byteoffset})";;
+    (*emacs*) ${=editor} -eval "(progn (find-alternate-file ${(qqq)1}) (goto-char ${byteoffset}))";;
     (*) ${=editor} $1;;
   esac
 


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

* Re: edit-command-line problem with emacsclient
       [not found]   ` <55FF3CE5.9070604@petervasil.net>
@ 2015-09-21  4:06     ` Bart Schaefer
       [not found]       ` <56004B05.9000703@petervasil.net>
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2015-09-21  4:06 UTC (permalink / raw)
  To: zsh-workers; +Cc: Peter Vasil

On Sep 21,  1:10am, Peter Vasil wrote:
}
} This works but it's not optimal since the emacs window doesn't get
} raised and doesn't come to front. And also the terminal is not waiting
} for Emacs to return.

I guess this means there's no set of common options we can use.  Sigh.

(How nice that "emacsclient -nw" and "emacs -nw" mean almost exactly
the opposite of one another.)

So you'll have to help here a little -- would you expect --create-frame
or --tty ?  Given the context I'd probably chose --tty, but either one
seems to force emacsclient to wait for the frame to close.


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

* Re: edit-command-line problem with emacsclient
       [not found]         ` <150921120017.ZM426@torch.brasslantern.com>
@ 2015-09-21 19:09           ` Peter Vasil
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Vasil @ 2015-09-21 19:09 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

Hi Bart,

Yes. both emacs and emacsclient accept [+LINE[:COLUMN]] FILENAME, so
that could be used in order to have only one case label for both.

Bests,
Peter


On 09/21/2015 09:00 PM, Bart Schaefer wrote:
> (Including Peter's entire message below because it didn't go to the list.)
> 
> On Sep 21,  8:23pm, Peter Vasil wrote:
> }
> } I think for Emacs the current solution is the best and I would vote to
> } leaving it like it is right now.
> 
> Yes, we'll probably have to add another case-label for emacsclient.
> Except:
> 
> } emacsclient however accepts line and column alogn with the file name
> } like this: emacsclient [+LINE[:COLUMN]] FILENAME
> 
> Ah!  My manual page for emacsclient doesn't mention that.  Emacs also
> accepts that.  So we could replace "-eval (goto-char ...)" in both
> cases, and avoid having to split them?
> 
> 
> 
> 
> --- Forwarded mail from Peter Vasil <mailing_lists@petervasil.net>
> 
> Subject: Re: edit-command-line problem with emacsclient
> To: Bart Schaefer <schaefer@brasslantern.com>
> From: Peter Vasil <mailing_lists@petervasil.net>
> Date: Mon, 21 Sep 2015 20:23:01 +0200
> 
> Hi,
> 
> I think for Emacs the current solution is the best and I would vote to
> leaving it like it is right now.
> 
> To be honest, for emacsclient I would rather prefer the simple $EDITOR
> $1 call than the suggested solutions here in this thread. This worked
> out best.
> 
> --create-frame or --tty depends really on the user's context, whether he
> uses the gui version or the terminal version. Do you really want to
> hardcode it in edit-command-line?
> 
> emacsclient however accepts line and column alogn with the file name
> like this: emacsclient [+LINE[:COLUMN]] FILENAME
> 
> Would it be possible to calculate LINE and COLUMN from byteoffset in zsh?
> 
> Bests,
> Peter
> 


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

* Re: edit-command-line problem with emacsclient
  2015-09-20 11:46 edit-command-line problem with emacsclient Peter Vasil
  2015-09-20 15:32 ` Bart Schaefer
@ 2015-09-21 21:16 ` Daniel Shahaf
  2015-09-21 22:31   ` Bart Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Shahaf @ 2015-09-21 21:16 UTC (permalink / raw)
  To: Peter Vasil; +Cc: zsh-workers

Peter Vasil wrote on Sun, Sep 20, 2015 at 13:46:26 +0200:
> Commit 35ffe36318955d03fca3df0d34a0997970cfc6a3 introduced the change,
> that when calling edit-command-line, the curser is put to the right offset.
> 

I wrote that.  Sorry for the bug.  I'm a vim user, and I sanity-tested
the emacs case, but I don't actually speak emacs lisp, so I'm not
surprised the patch was complete but not sound.  I see now I forgot to
state in the patch mail that the emacs codepath needed extra review :-/

Cheers,

Daniel
(OT: Perhaps I should add "I don't speak emacs lisp" to https://people.apache.org/~danielsh/bilmiyorum/?)

> This is implemented for vim and emacs, however if I set my EDITOR or
> VISUAL to emacsclient, the *emacs* condition gets called which does not
> work for emacsclient. The arguments specidied for emacs work only for
> Emacs but not for emacsclient.
> 
> It would be great to change the condition *emacs* that it does not match
> emacsclient or add another condition for emacsclient with appropriate
> arguments.
> 
> Thanks and bests,
> Peter
> 


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

* Re: edit-command-line problem with emacsclient
  2015-09-21 21:16 ` Daniel Shahaf
@ 2015-09-21 22:31   ` Bart Schaefer
  2015-09-22  7:10     ` Peter Vasil
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2015-09-21 22:31 UTC (permalink / raw)
  To: zsh-workers

On Sep 21,  9:16pm, Daniel Shahaf wrote:
}
} I wrote that.  Sorry for the bug.  I'm a vim user, and I sanity-tested
} the emacs case, but I don't actually speak emacs lisp, so I'm not
} surprised the patch was complete but not sound.  I see now I forgot to
} state in the patch mail that the emacs codepath needed extra review :-/

S'ok, I think this should do it:

diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 2c7f34b..103a1c1 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -11,13 +11,16 @@
 
   # Compute the cursor's position in bytes, not characters.
   setopt localoptions nomultibyte
-  integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
 
   # Open the editor, placing the cursor at the right place if we know how.
   local editor=${${VISUAL:-${EDITOR:-vi}}}
   case $editor in 
-    (*vim*) ${=editor} -c "normal! ${byteoffset}go" -- $1;;
-    (*emacs*) ${=editor} $1 -eval "(goto-char ${byteoffset})";;
+    (*vim*)
+      integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
+      ${=editor} -c "normal! ${byteoffset}go" -- $1;;
+    (*emacs*)
+      local lines=( ${(f):-"$PREBUFFER$LBUFFER"} )
+      ${=editor} +${#lines}:$((${#lines[-1]} + 1)) $1;;
     (*) ${=editor} $1;;
   esac
 


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

* Re: edit-command-line problem with emacsclient
  2015-09-21 22:31   ` Bart Schaefer
@ 2015-09-22  7:10     ` Peter Vasil
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Vasil @ 2015-09-22  7:10 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

Hi Bart,

Looks really good. I can confirm that your patch works for both emacs
and emacsclient.

Thanks so much!

Cheers,
Peter

On 09/22/2015 12:31 AM, Bart Schaefer wrote:
> On Sep 21,  9:16pm, Daniel Shahaf wrote:
> }
> } I wrote that.  Sorry for the bug.  I'm a vim user, and I sanity-tested
> } the emacs case, but I don't actually speak emacs lisp, so I'm not
> } surprised the patch was complete but not sound.  I see now I forgot to
> } state in the patch mail that the emacs codepath needed extra review :-/
>
> S'ok, I think this should do it:
>
> diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
> index 2c7f34b..103a1c1 100644
> --- a/Functions/Zle/edit-command-line
> +++ b/Functions/Zle/edit-command-line
> @@ -11,13 +11,16 @@
>  
>    # Compute the cursor's position in bytes, not characters.
>    setopt localoptions nomultibyte
> -  integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
>  
>    # Open the editor, placing the cursor at the right place if we know how.
>    local editor=${${VISUAL:-${EDITOR:-vi}}}
>    case $editor in 
> -    (*vim*) ${=editor} -c "normal! ${byteoffset}go" -- $1;;
> -    (*emacs*) ${=editor} $1 -eval "(goto-char ${byteoffset})";;
> +    (*vim*)
> +      integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
> +      ${=editor} -c "normal! ${byteoffset}go" -- $1;;
> +    (*emacs*)
> +      local lines=( ${(f):-"$PREBUFFER$LBUFFER"} )
> +      ${=editor} +${#lines}:$((${#lines[-1]} + 1)) $1;;
>      (*) ${=editor} $1;;
>    esac
>  


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

end of thread, other threads:[~2015-09-22  7:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-20 11:46 edit-command-line problem with emacsclient Peter Vasil
2015-09-20 15:32 ` Bart Schaefer
     [not found]   ` <55FF3CE5.9070604@petervasil.net>
2015-09-21  4:06     ` Bart Schaefer
     [not found]       ` <56004B05.9000703@petervasil.net>
     [not found]         ` <150921120017.ZM426@torch.brasslantern.com>
2015-09-21 19:09           ` Peter Vasil
2015-09-21 21:16 ` Daniel Shahaf
2015-09-21 22:31   ` Bart Schaefer
2015-09-22  7:10     ` Peter Vasil

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).