I'm trying to bind M-[
and M-]
to the following functions (courtesy of Xah Lee):
(defun xah-forward-block (&optional n)
"Move cursor beginning of next text block.
A text block is separated by blank lines.
This command similar to `forward-paragraph', but this command's behavior is the same regardless of syntax table.
URL `http://ergoemacs.org/emacs/emacs_move_by_paragraph.html'
Version 2016-06-15"
(interactive "p")
(let ((n (if (null n) 1 n)))
(re-search-forward "\n[\t\n ]*\n+" nil "NOERROR" n)))
(defun xah-backward-block (&optional n)
"Move cursor to previous text block.
See: `xah-forward-block'
URL `http://ergoemacs.org/emacs/emacs_move_by_paragraph.html'
Version 2016-06-15"
(interactive "p")
(let ((n (if (null n) 1 n))
($i 1))
(while (<= $i n)
(if (re-search-backward "\n[\t\n ]*\n+" nil "NOERROR")
(progn (skip-chars-backward "\n\t "))
(progn (goto-char (point-min))
(setq $i n)))
(setq $i (1+ $i)))))
(global-set-key (kbd "<M-[>") 'xah-backward-block)
(global-set-key (kbd "<M-]>") 'xah-forward-block)
After I add the above code to the init file and save, and then do M-x eval-buffer
or restart, it doesn't take effect. When I try to move or look them up via C-h k
it says M-[
or M-]
is undefined. But I can see them listed in the describe-bindings buffer via C-h b
. I also tried to escape the brackets as \[
and \]
because I thought maybe they're special characters, but still I've got the same result. But when I change the brackets to arrow keys it works. The version of Emacs I use is 26.2 and OS is Fedora 30. I've checked a lot of places and still haven't found the solution.