Emacs everywhere rewrite?

I used Emacs Everywhere on KDE and it worked well. However, since I
moved to Sway, it has been a struggle to get it working. I eventually
gave up on trying to make it work and wrote this make shift version in
my configuration instead.

My makeshift version currently types the content into the window
below. It seems to work well on Sway, since it automatically switches
focus to the correct text area after the frame is deleted. Emacs
Everywhere copies the text into the clipboard and then pastes it into
the text area; I think it also manually switches focus.

I was wondering if I should create a separate package for this,
exclusive to Sway or potentially other Wayland compositors, provided
it doesn’t require too much work.

1 Like

I was looking forward for this PR; Dotool support by msin32 · Pull Request #92 · tecosaur/emacs-everywhere · GitHub

I use niri as wm. Maybe with few tweaks we can get it working.

But previously to get similar functionality, I was using a custom keybind in WM to open emacsclient on some tmp/scratch file. Then with save and exit, wtype or dotool would insert those content into the browser or wherever focus is.

But still i dont find usecase for it, as I always have emacs window open. Manually i just do copy and paste if I really need emacs editing.

1 Like

I use niri as wm. Maybe with few tweaks we can get it working.

I think the current code will just work™.

But previously to get similar functionality, I was using a custom
keybind in WM to open emacsclient on some tmp/scratch file. Then with
save and exit, wtype or dotool would insert those content into the
browser or wherever focus is.

I never save, I directly ask wtype to write the contents of the buffer
into whatever the focus is. I do not like the copy paste nature of
emacs-everywhere, because it is not universal (many programs have
different keybindings for copy-paste).

But still i dont find usecase for it, as I always have emacs window
open. Manually i just do copy and paste if I really need emacs
editing.

Same here, but emacs-everywhere is just more convenient. I can say
that after using my make-shift version for a while.

1 Like

@zororg, Did you try it out yet?

Hey Hi. Sorry for delayed response.

Ya i tried your make shift version which works like charm.

I could not get emacs-everywhere, since I use niri wm, I need to write own function.

Thank for the heads up, I think I will make use of it

1 Like

If it works like a charm, why do you need to write own function? Can
you clarify what adjustments you had to make?

Thats not what I meant.
I meant, your make-shift version (ECFPAW/ee) works like charm. Instead of wtype I replaced it with dotool.

I could not get emacs-everywhere, since I use niri wm, I need to write own function.

Then I meant, with OG emacs-everywhere package by tecosaur, it did not work. Since it only has functions for Sway and KDE.
Some custom function is required to get windows from WM i guess.

Wow, didn’t know about it.

Do you think we should package this code separately? I guess we can
make it support both wtype and dotool. I think tinee (This Is Not
Emacs Everywhere), as in it is not as featureful as Emacs Everywhere,
but it is tiny as a result, is a good name.

Yeah sounds good.
You can make it as package, support it with an blog post (or readme) and share with emacs community (reddit & mailing lists)

Edit: A caution: I have to admit that this might have unexpected outcome as well.

I think it was due to how dotool works or it did not read string properly.
I had different keybindings pressed doing many things to my system.
I guess it was due to not double quoting my input (bash) and word splitting

okay, as I try it again. Looking at emacs-everywhere code, I think copy to clipboard is reliable than auto typing the content.

I make use of GitHub - sentriz/cliphist: Wayland clipboard manager with support for multimedia (cliphist) very much with fuzzel.
So I modified it in a way that creates files in tmp dir, and copies the content to kill-ring.

Here is my version: d-nix/d-setup.org at gol-d · idlip/d-nix · GitHub

Happens to me sometimes as well. Also, just pass the arguments
directly instead of going through the shell.

Even if we were to do it. Why not do it like this?

  1. Call gui-select-text with buffer text.
  2. Run C-v using wtype.

Why do you need to go through, a temp file, another external program,
etc?

1 Like
(defun ECFPAW/ee-paste (string)
  "Paste STRING into Wayland windows from within Emacs."
  (let ((select-enable-primary t)
	(select-enable-secondary nil))
    (gui-select-text string))
  (start-process "ee-paste" nil 
		 "wtype" "-s" "500" "-M" "Shift" "-P" "Insert"
		 "-m" "Shift" "-p" "Insert"))

(defun ECFPAW/ee-done (&optional arg)
  "Write the current buffer using `ECFPAW/ee-write'.

  If ARG is 4, export the buffer as Markdown. Otherwise, directly use
  the org markup.

  This function deletes the current frame after pasting the text."
  (interactive "p")
  (require 'ox-md)
  (let* ((raw-text (buffer-substring-no-properties (point-min) (point-max)))
	 ;; No idea why the 3rd argument of `org-export-with-toc' doesn't work for this.
	 (org-export-with-toc nil)
	 (text (pcase arg
		 (4  (org-export-string-as raw-text 'md t))
		 (_  raw-text))))
    (delete-frame)
    (ECFPAW/ee-paste text)))

(define-minor-mode ECFPAW/ee-mode
  "ee minor mode"
  :keymap `((,(kbd "C-c C-c") . ECFPAW/ee-done)))

(defun ECFPAW/ee ()
  "Start ee."
  (with-current-buffer
      (get-buffer-create (format "ee-%d"
				 (time-convert (current-time) 'integer)))
    (org-mode)
    (ECFPAW/ee-mode)
    (modify-frame-parameters
     (make-frame '((name . "ee -float-")))
     '((width . 80)
       (height . 20)))))

Can you try this out? I tried implementing the copy paste version. But
it doesn’t work for firefox (works on other windows).

Actually, just try the package instead:

You can configure which method it uses.

1 Like