Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added emacs as an "operating system" for input mode. #16949

Merged
merged 10 commits into from
Aug 14, 2022

Conversation

chewxy
Copy link

@chewxy chewxy commented Apr 27, 2022

I added a new unicode input mode: emacs.

While strictly not an operating system, inserting unicode characters in emacs has its own keybinding. The most usual way is C-x-8 RET followed by the unicode in hex. As a person who works across different OSes but with the constant being emacs, this was the most straightforward way forwards.

Of course, the main credit goes to TrentinQuarantino in this emacs stack exchange post.

Description

I added a new unicode input mode in quantum/process_unicode_common.(c|h). Then I updated all the programmer friendly numbers of the enums, and added documentation too.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Additional notes

I'm unfamiliar with the testing protocols of this project. If I could get some help that'd be great. I'm reasonably familiar with C. However, what I have done is I have flashed two ergodox-EZs with this and tested it on emacs on both linux and macos. My Windows computer isn't quite available right now, so I'm unable to test on Windows.

@zvecr zvecr changed the base branch from master to develop April 27, 2022 12:15
quantum/quantum_keycodes.h Outdated Show resolved Hide resolved
@zvecr
Copy link
Member

zvecr commented Apr 27, 2022

Previous implementation, #8358.

@drashna
Copy link
Member

drashna commented Apr 27, 2022

Is there a reason that the "linux" mode can't be used, with a custom start/finish option?

Eg

void unicode_input_start(void) {
    unicode_saved_caps_lock = host_keyboard_led_state().caps_lock;
    unicode_saved_num_lock  = host_keyboard_led_state().num_lock;

    if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) {
        tap_code(KC_CAPS_LOCK);
    }

    unicode_saved_mods = get_mods(); // Save current mods
    clear_mods();                    // Unregister mods to start from a clean state

    switch (unicode_config.input_mode) {
        case UC_MAC:
            register_code(UNICODE_KEY_MAC);
            break;
        case UC_LNX:
            tap_code16(LCTL(KC_X));
            tap_code16(KC_8);
            tap_code16(KC_ENTER);
            break;
        case UC_WIN:
            // For increased reliability, use numpad keys for inputting digits
            if (!unicode_saved_num_lock) {
                tap_code(KC_NUM_LOCK);
            }
            register_code(KC_LEFT_ALT);
            wait_ms(UNICODE_TYPE_DELAY);
            tap_code(KC_KP_PLUS);
            break;
        case UC_WINC:
            tap_code(UNICODE_KEY_WINC);
            tap_code(KC_U);
            break;
    }

    wait_ms(UNICODE_TYPE_DELAY);
}

@chewxy
Copy link
Author

chewxy commented Apr 27, 2022

@drashna as far as I am aware, ibus on linux only allows Alt+HEXCODE entries, whereas emacs in general requires the C-x-8 RET sequence followed by the hex code

@chewxy
Copy link
Author

chewxy commented Apr 27, 2022

(having said that, if you have gnome-tweak-tool or gconf-editor on any linux with gnome (e.g. ubuntu), you can turn on Emacs Input and the Ctrl+x+8 ENTER sequence also allows you to type unicode.)

But we'd probably still want to keep the default ibus settings for normal people

@tzarc tzarc requested review from a team and zvecr August 13, 2022 14:14
chewxy and others added 8 commits August 14, 2022 20:13
Credit to user TrentinQuarantino at the emacs stack exchange: https://emacs.stackexchange.com/a/56027
    - moved the enum `UNICODE_MODE_EMACS` to just before `SAFE_RANGE`
    which makes it safe for things like VIA to work with
      - moved the enum `UNICODE_MODE_EMACS` to just before
      `SAFE_RANGE` so that things like VIA can work properly
      - previous commit was a careless merge from the wrong master
      branch. This commit fixes that
not use the nonstandard C of using `...` in the case statement, which
requires the enums of the unicode input mode to be in a specific order
@zvecr zvecr merged commit 6fc7c03 into qmk:develop Aug 14, 2022
nolanseaton pushed a commit to nolanseaton/qmk_firmware that referenced this pull request Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants