3

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.

0

1 Answer 1

7

Substrings in the kbd argument that are delimited by < and > are labels for non-character input events such as <mouse-2>. But, with [ you mean the character [ and with M- you mean the meta modifier. So < and > are inappropriate in your use-case.

Use (kbd "M-[") instead of (kbd "<M-[>").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.