1

I'm trying to write my own major mode, which I want to use under MS Windows. Unfortunately, Windows doesn't have my favourite keyboard layout, so I'm planning to implement this keyboard layout in my major mode. For that, I'm trying to create a full keymap and modify its char-table, but I don't know, how to do this. I've tried this so far, but when I try to use this keymap, the keys a and v don't function at all:

(defvar aplc-mode-map
  (let ((map (make-keymap)))
    (define-key map (kbd "a") (kbd "v"))
    (define-key map (kbd "v") (kbd "a"))
    map))

My favourite method would be to replace a region of the char-table, but I don't know how I can modify that char-table directly. Can someone help me?

P.s.: OK, since maybe my question wasn't specific enough, here is the code I have so far (which does nothing, really):

(defvar aplc-mode-map
  (let ((map (make-keymap)))
    map)
  "Keymap for APL mode.")

(define-derived-mode aplc-mode fundamental-mode "APLc"
  "Major mode for editing APL code on windows

\\{aplc-mode-map}"

  )

(provide 'aplc-mode)

I want to redefine (almost) all keys on the keyboard, not just action keys or shortcuts. I want, that even if the system keyboard layout is "English (US)", I can write in emacs as if the layout was "Dvorak". For that, I want to define a keymap, that - for example - redefines the key "s" as being the key "o".

My problem is, how I can access the char-table and change its values.

Hopefully, this makes the question clearer...

By the way: The question doesn't have anything to do with Windows in particular (at the moment I'm trying to implement this under linux), but the implementation only makes sense under Windows, since under linux I can just change the keyboard layout, but under Windows the keyboard layout is not installed.

P.s.2: OK, this is the code that I have so far. Now I can replace any character with any other character that I want it to be. The remaining question is posted below.

(defvar aplc-mode-map nil "Keymap for APL mode.")

(progn
  (setq aplc-mode-map (make-keymap))
  (define-key aplc-mode-map [65] (lambda () (interactive) (insert "A")))
  (define-key aplc-mode-map [66] (lambda () (interactive) (insert "B")))
  (define-key aplc-mode-map [67] (lambda () (interactive) (insert "C")))
  (define-key aplc-mode-map [68] (lambda () (interactive) (insert "D")))
  (define-key aplc-mode-map [69] (lambda () (interactive) (insert "E")))
  (define-key aplc-mode-map [70] (lambda () (interactive) (insert "F")))
  (define-key aplc-mode-map [71] (lambda () (interactive) (insert "G")))
  (define-key aplc-mode-map [72] (lambda () (interactive) (insert "H")))
  (define-key aplc-mode-map [73] (lambda () (interactive) (insert "I")))
  (define-key aplc-mode-map [74] (lambda () (interactive) (insert "J")))
  (define-key aplc-mode-map [75] (lambda () (interactive) (insert "K")))
  (define-key aplc-mode-map [76] (lambda () (interactive) (insert "L")))
  (define-key aplc-mode-map [77] (lambda () (interactive) (insert "M")))
  (define-key aplc-mode-map [78] (lambda () (interactive) (insert "N")))
  (define-key aplc-mode-map [79] (lambda () (interactive) (insert "O")))
  (define-key aplc-mode-map [80] (lambda () (interactive) (insert "P")))
  (define-key aplc-mode-map [81] (lambda () (interactive) (insert "Q")))
  (define-key aplc-mode-map [82] (lambda () (interactive) (insert "R")))
  (define-key aplc-mode-map [83] (lambda () (interactive) (insert "S")))
  (define-key aplc-mode-map [84] (lambda () (interactive) (insert "T")))
  (define-key aplc-mode-map [85] (lambda () (interactive) (insert "U")))
  (define-key aplc-mode-map [86] (lambda () (interactive) (insert "V")))
  (define-key aplc-mode-map [87] (lambda () (interactive) (insert "W")))
  (define-key aplc-mode-map [88] (lambda () (interactive) (insert "X")))
  (define-key aplc-mode-map [89] (lambda () (interactive) (insert "Y")))
  (define-key aplc-mode-map [90] (lambda () (interactive) (insert "Z")))
  (define-key aplc-mode-map [97] (lambda () (interactive) (insert "a")))
  (define-key aplc-mode-map [98] (lambda () (interactive) (insert "b")))
  (define-key aplc-mode-map [99] (lambda () (interactive) (insert "c")))
  (define-key aplc-mode-map [100] (lambda () (interactive) (insert "d")))
  (define-key aplc-mode-map [101] (lambda () (interactive) (insert "e")))
  (define-key aplc-mode-map [102] (lambda () (interactive) (insert "f")))
  (define-key aplc-mode-map [103] (lambda () (interactive) (insert "g")))
  (define-key aplc-mode-map [104] (lambda () (interactive) (insert "h")))
  (define-key aplc-mode-map [105] (lambda () (interactive) (insert "i")))
  (define-key aplc-mode-map [106] (lambda () (interactive) (insert "j")))
  (define-key aplc-mode-map [107] (lambda () (interactive) (insert "k")))
  (define-key aplc-mode-map [108] (lambda () (interactive) (insert "l")))
  (define-key aplc-mode-map [109] (lambda () (interactive) (insert "m")))
  (define-key aplc-mode-map [110] (lambda () (interactive) (insert "n")))
  (define-key aplc-mode-map [111] (lambda () (interactive) (insert "o")))
  (define-key aplc-mode-map [112] (lambda () (interactive) (insert "p")))
   (define-key aplc-mode-map [113] (lambda () (interactive) (insert "q")))
  (define-key aplc-mode-map [114] (lambda () (interactive) (insert "r")))
  (define-key aplc-mode-map [115] (lambda () (interactive) (insert "s")))
   (define-key aplc-mode-map [116] (lambda () (interactive) (insert "t")))
  (define-key aplc-mode-map [117] (lambda () (interactive) (insert "u")))
  (define-key aplc-mode-map [118] (lambda () (interactive) (insert "v")))
  (define-key aplc-mode-map [119] (lambda () (interactive) (insert "w")))
  (define-key aplc-mode-map [120] (lambda () (interactive) (insert "x")))
  (define-key aplc-mode-map [121] (lambda () (interactive) (insert "y")))
  (define-key aplc-mode-map [122] (lambda () (interactive) (insert "z")))
  (define-key aplc-mode-map [49] (lambda () (interactive) (insert "1")))
  (define-key aplc-mode-map [50] (lambda () (interactive) (insert "2")))
  (define-key aplc-mode-map [51] (lambda () (interactive) (insert "3")))
  (define-key aplc-mode-map [52] (lambda () (interactive) (insert "4")))
  (define-key aplc-mode-map [53] (lambda () (interactive) (insert "5")))
  (define-key aplc-mode-map [54] (lambda () (interactive) (insert "6")))
  (define-key aplc-mode-map [55] (lambda () (interactive) (insert "7")))
  (define-key aplc-mode-map [56] (lambda () (interactive) (insert "8")))
  (define-key aplc-mode-map [57] (lambda () (interactive) (insert "9")))
  (define-key aplc-mode-map [58] (lambda () (interactive) (insert "0")))

  )

(define-derived-mode aplc-mode fundamental-mode "APLc"
  "Major mode for editing APL code on windows

\\{aplc-mode-map}"

  (use-local-map aplc-mode-map)

  )

(provide 'aplc-mode)

Now I have to figure out how I can combine (for example) keycode [65] with a meta key.

  • Show your code that tries to modify the char-table, and explain why you want to do that. Why not just bind the keys directly to the commands you want? – Drew Sep 20 '18 at 17:42
  • You example shows you trying to swap a and v. Are you really trying to swap keys? You're talking about keyboard layout, but then your example is about setting up a major-mode (the two are traditionally orthogonal), please clarify why they are linked. Finally, I hope you're aware that there is already a major mode for APL, so if this doesn't do what you want, you can describe your problems in terms of what that major mode fails to do for you. – Stefan Sep 20 '18 at 18:58
  • I actually wanted to swap keys "a" and "v" (as an example), but the code does not work. The problem with APL major mode is that it fails to provide a keyboard layout, that lets me input APL characters. Under linux, this is no problem since I can just change the keyboard layout in the OS settings, but in Windows, so I can't install a new keyboard layout (I'm no adminastrator) (and I don't like Dyalogs editor). So my idea was to provide a suitable keyboard layout within an APL major mode that lets me input APL characters. I found a partial solution to my problem, which I will post in a minute. – user3617992 Sep 20 '18 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.