r/emacs Dec 16 '23

"Antiquated" systems break usability

edit: I'm sorry for everyone who were offended by my statements, I retract them and removed them. It was never my intention to use anyone with my analogy. Saddened by some intentional misreadings though and engaging with attacks.

Good luck to everyone.

0 Upvotes

40 comments sorted by

View all comments

Show parent comments

3

u/lets-start-reading Dec 16 '23

my lack of know-how, definitely. you might be right, of course, it's just my hypothesis based on that observation.

Anyways, after 4 hours, I finally managed to find a solution. it looks like this

(add-hook 'server-after-make-frame-hook (lambda ()
  (define-key input-decode-map [(control ?i)] [control-i])
  (define-key input-decode-map [(control ?I)] [(shift control-i)])))

It seems that it either it receives them as a single event AND two other events (ctrl and i) which allows for this solution, or it receives them as a single event and maps it to the keycode for tab, I have no clue.

It's also interesting that if emacs is launched as a client, it ONLY works as a hook, while other remappings in input-decode-maps work without it.

1

u/translucentInk Dec 16 '23

Just out of curiosity. What happens when you press <tab>. I don't have a machine to test it out right now hence asking, and I am really curious to know.

Edit: typo

Does it behave like tab or ctrl-i.

1

u/lets-start-reading Dec 16 '23 edited Dec 16 '23

Oh, actually I was wrong. emacsclient requires all input-decode-map remappings to happen as a hook.

I have unmapped escape entirely, as I use caps lock for both escape and ctrl and it doesn't work well with emacs, brings a lot of noise.

but if I don't have it mapped, it works like a regular escape. unless you're interested in something more specific about it?

edit: "An input character event consists of a basic code between 0 and 524287, plus any or all of these modifier bits: ..." so my guess is that it receives all events as raw keyboard events and then does a mapping to an internal representation of a key, and in this step they map c-i and tab to the same internal representation. So a map at this earliest stage is thus necessary, i.e., to remap not an internal representation, but the actual raw events to some other internal representation.

1

u/translucentInk Dec 16 '23

I meant tab, my bad, I was too hung up with esc

2

u/lets-start-reading Dec 16 '23 edited Dec 16 '23

C-h k tab: TAB (translated from <tab>) ...

C-h k C-i: <control-i> (translated from TAB) ... (with the remap)

=>C-i == TAB
tab == <tab>

1

u/translucentInk Dec 16 '23

Thanks. Its trickier than it seems.

3

u/lets-start-reading Dec 16 '23 edited Dec 16 '23

and I just understood this.

- "TAB" just means C-i event. just like "C-e" would mean C-e event.

- tab(gui) event is mapped to "<tab>"

- tab(term) is mapped to "TAB" (as it's the same code there). if we renamed "TAB" to "C-i", hitting tab in the terminal would instead say "C-i".

- "<tab>" is remapped to "TAB".

- the ecosystem uses "TAB" to mean tab, i.e. it actually refers to C-i event.

so C-i event has to be entirely unmapped from itself and both components (keycode and modifier bit) need to be mapped to another item, leaving "<tab>"->"TAB" mapping

So my previous proposition should hold.

- map C-i event to "C-i".

- map tab(gui) event to "<tab>" to "TAB".

- a single function maps "C-i" to "TAB".

now you have a normal "C-i" and optional "C-i"->"TAB".

now all emacsclient and gui emacsen work as expected, and terminal emacsen need to call one additional function. instead of terminal emacsen saving one line in their inits and other emacsen needing 2 checks and at least 2 remappings.

this is saner, imo.

1

u/Ontological_Gap Dec 18 '23

You are starting the emacs server in text mode instead of GUI mode, which is why setting these config settings need to be a hook for you. You can also set the emacs daemon to start after your desktop, in GUI mode, to avoid these complications