I wrote a couple of functions to automatically convert sequences like "<<"
in «
. (Yeah, I know that input methods can do the same, but I don't want the extra bindings: I'm planning to use a lot of apostrophes, and I don't want them to be joined).
So far, I have my functions:
(defun electric-left-angle ()
"Insert a left angle bracket ('<') and, if doubles, converts it to an open guillemet ('«')."
(interactive)
(if (equal (char-before (point)) #x3c);;code for <
(progn
(delete-char -1) ;;TODO see doc
(insert-char #x00ab 1 t)) ;;code for «
(insert-char #x3c 1 t)))
(defun electric-right-angle ()
"Insert a right angle bracket ('>') and, if double, converts it to a close guillemet ('»')."
(interactive)
(if (equal (char-before (point)) #x3e);;code for >
(progn
(delete-char -1) ;;TODO see doc
(insert-char #x00bb 1 t)) ;;code for »
(insert-char #x3e 1 t)))
which works fine.
Then I thought "What if I want to insert a literal sequence <<
? So I also created these:
(defun quoted-insert-left-angle-bracket ()
"Insert the quoted char '<'."
(interactive)
(progn (insert-char #x3c 1 t)))
(defun quoted-insert-right-angle-bracket ()
"Insert the quoted char '>'."
(interactive)
(progn (insert-char #x3e 1 t)))
and these works fine too.
The problem arises when I try to bind these functions in a custom minor mode:
(define-minor-mode narrative-mode
"A minor mode that overrides the angle brackets insertion, changing them to guillemets.
Binds '<' and '>' to specific functions, which converts \"<<\" to '«' and \">>\" to '»'. Normal angle brackets can be inserted with C-< and C->."
:lighter " narr"
:keymap '(((kbd "<") . electric-left-angle)
((kbd ">") . electric-right-angle)
((kbd "C-<") . quoted-insert-left-angle-bracket)
((kbd "C->") . quoted-insert-right-angle-bracket)))
When I activate this mode, pressing < < does indeed insert «
. But pressing C + < reports C-< is undefined
in the echo area. Why?
Further information
Notice that investigating with C-h k C-<
gives C-< is undefined
, but C-h f quoted-insert-left-angle
gives
quoted-insert-left-angle-bracket is an interactive Lisp function in
‘../init.el’.
It is bound to C - <.
(quoted-insert-left-angle-bracket)
Insert the quoted char ’<’.
(notice the unusual odd space in "C - <"
.
Moreover, assigning the function globally with (global-set-key (kbd "C-<") #'quoted-insert-left-angle-bracket)
works fine, so I suppose it's a problem of how I bind the functions in the minor mode.
I'm using GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.17.4) of 2021-03-26.