My I3-Emacs Integration

(khz.ac)

87 points | by nosolace 14 hours ago ago

32 comments

  • SubiculumCode 11 hours ago ago

    Side note: I am really enjoying HN today with the set of stories with personal hacks like this i3-emacs integration, someone's desk setup, someone's writer-deck laptop install, the kinda hilarious but also hecka geeky thermal ttrpg thingamabob, and the 16 byte wake up demo. Fun geeky stuff that isn't AI,and I love AI, but it ain't everything.

  • krupan an hour ago ago

    In case you don't understand the problem here, an emacs instance can be split into multiple "windows" and there are emacs key bindings to create and destroy these windows, move the "focus" from one window to another, resize the windows, etc. For many of us, this was our introduction to a tiling window manager experience before we'd ever heard of tiling window managers.

    When we switched to using a tiling window manager for all our windows, we ran into a muscle memory problem. We were used to jumping between emacs windows/buffers using C-x o and C-x b and then without thinking about it we'd try and use the same keys to jump between i3/sway windows and of course it doesn't work. Or vice versa, trying to use i3/sway shortcuts to switch emacs windows/buffers.

    To try and solve this problem I've been using less emacs windows and more i3/sway windows, so I can just use i3/sway keybindings everywhere, but emacs puts up some resistance to that. I like this approach

    • cmrdporcupine 22 minutes ago ago

      Yep, I still find emacs' window management bindings more intuitive than any tiling window manager I've used. So much so that I thought naively that things like exwm would "solve" this problem for me. But in fact -- beyond being janky / single-threaded -- they don't really because you still end up with competing bindings.

      I think the more elegant model would be for the window manager to own all the window management keybindings and then for there to be a background emacs-like process that owns the buffers (and the remaining keybindings) and can present them in standalone windows which the window manager presents. With some kind of IPC between the two for coordination, I guess.

      I don't think GNU Emacs itself works well with this model tho. Its "server" mode is something else entirely.

  • timonoko 5 hours ago ago

    Unrelated, but me and Gemini just invented "C-x 4" for multiscreens.

      (defun my-external-readonly-split ()
        "Open the current file in an external xfce4-terminal as read-only."
        (interactive)
        (if buffer-file-name
            (start-process "xfce-terminal-split" nil 
                           "xfce4-terminal" "-x" "emacs" "-nw" 
                           "--eval" "(find-file-read-only (pop command-line-args-left))"
                           buffer-file-name)
          (message "Current buffer is not visiting a file!")))
    
      (global-set-key (kbd "C-x 4") 'my-external-readonly-split)
    • the-lazy-guy an hour ago ago

      You should use emacsclient, so file will be actually shared. Or better yet - use GUI emacs with its ability to have multiple frames.

      • timonoko an hour ago ago

        No Thank You

          export EDITOR="emacs -nw"
        • krupan an hour ago ago

          export EDITOR="emacsclient -nw"

          It really speeds things up

    • timonoko 5 hours ago ago

      Incredibly splendid. I just tested it myself.

      Try C-x 2, C-x 3 and C-x 4

  • Zambyte 5 hours ago ago

    Ooo this is nice. I may have to try to get this working with my personal setup using Emacs and Sway.

    My long term vision is to make an Emacs implementation that is compatible only in philosophy. It would use Guile instead of Elisp, default to bindings that are more familiar to people coming from more modern systems, and would be built from the beginning with concurrency and graphics in mind. For now it remains a dream though.

    • krupan an hour ago ago
    • volemo 3 hours ago ago

      I know, right? However, one of the strongest points of Emacs is the huge amount of existing packages.

    • grumpyprole 5 hours ago ago

      VSCode is pretty much this. But with typescript instead of Guile. After 30 years of Emacs, I switched .

      • krupan 43 minutes ago ago

        Heresy! ;)

        I would guess you hadn't done as much emacs yak shaving as some of us other emacs users if the switch to VSCode was a simple one

      • bergheim 4 hours ago ago

        after 30 years you say this? this cannot be serious.

    • cmrdporcupine 5 hours ago ago

      Sounds like you want Lem. Though it's common lisp instead of guile.

      https://github.com/lem-project/lem

  • nesarkvechnep 4 hours ago ago

    I did the same integration with an Erlang daemon. All relevant key presses are sent to it and based on the current focused application the daemon does different things. I built an Erlang library i3_IPC to listen for events and send commands to Sway.

    • krupan 31 minutes ago ago

      Care to share?

  • skulk 12 hours ago ago

    I've started using ewm to get this kind of unification between emacs window management and non-emacs window management.

    https://codeberg.org/ezemtsov/ewm

    • krupan 33 minutes ago ago

      "Writing a Wayland compositor from scratch is a staggering amount of work..."

      I switched to Wayland and sway about 2 years ago and it hasn't been bad, but this is the thing that makes me most sad about Wayland. X has so many different window manager options, it's like, an embarrassment of wealth. Wayland has like, 3 "finished" ones (if sway even counts).

    • stebalien 9 hours ago ago

      I keep trying it (coming from EXWM) but I get lots of lag, stutters, and poor fractional scaling. I'm not sure how much of that is "GTK under wayland", Emacs's PGTK build (known to have lag/rendering issues), AMD kernel drivers (?), or EWM itself; but it's not yet a replacement for EXWM in my experience.

  • PunchyHamster 13 hours ago ago

    I just use super(win key)/hyper (bound to capslock) for i3-related commands and leave emacs to its own devices with normal binds

    • krupan an hour ago ago

      The problem some of us have is we get used to jumping between emacs windows/buffers using C-x o and C-x b and then without thinking about it try and use the same keys to jump between i3 windows and of course it doesn't work. Or vice versa, trying to use i3 shortcuts to switch emacs windows/buffers.

    • noosphr 12 hours ago ago

      There can never be too many modifier keys:

      https://xcancel.com/octonion/status/1341113219142828039

    • topaz0 9 hours ago ago

      That's fine as far as it goes, but I don't think that gets you what this article is for, which is things like using the same binding context-dependently to navigate between emacs splits and regular window manager windows, context-dependently. Which is a fun bit of overengineering.

    • rileymat2 12 hours ago ago

      Yes, I am misunderstanding the problem. The windows/mac command key leave shift, control and alt free for i3.

    • royal__ 13 hours ago ago

      Yeah this is what I do. This article feels like crazy overengineering for something that's not really a problem

      • dima55 12 hours ago ago

        A dedicated key for all window-manager things is what people that have thought about it do (I use the "windows" key). But keyboard manufacturers haven't thought about it, so sometimes reasonable things aren't possible. I don't know.

      • sudahtigabulan 7 hours ago ago

        Unless you have RSI. Then it might be worth it. Depends on what hurts.

  • gigatexal 8 hours ago ago

    Ah no video it action??

    Very interesting though. I don’t always read entire posts on blogs but this one I did. Lisp looks really interesting.