emacs (osx + iterm2) define-key input-decode-map deprecated? - emacs

I have following define-key for iterm2 - emacs use.
(define-key input-decode-map "\e[1;31" (kbd "C-;"))
(define-key input-decode-map "\e[1;32" (kbd "C-="))
(define-key input-decode-map "\e[1;33" (kbd "C-:"))
After I upgrade emacs 24.5.1 it stopped working.
What's the correct syntax for it?
EDIT
I used 24.3 before
c-h l gives
b RET C-a C-n C-n C-n C-n C-x b i n p u t C-g C-x C-f DEL DEL DEL ~ /
. e m a c RET C-d ESC x m a g i t - s t a t u s RET g C-a C-n C-n C-n
C-n C-n C-n C-n C-n TAB TAB TAB TAB TAB TAB k y g C-a C-n C-n C-p C-p
C-p C-n C-p C-a C-n C-n C-x o C-c g s m a r t SPC p a r e n s C-g C-g
C-n C-n C-n C-x ESC p s m a r t SPC p a r e n RET C-a C-n C-x d RET g
C-a C-n C-n C-n C-p C-p C-s s m a r t - p a C-a C-s C-a C-n C-n C-a
C-x ESC p s m a r t C-n C-n C-n C-g RET g ^ R R O O T _ o r i g RET
ESC ! s h e l l RET C-g ESC ! e C-g ESC x s h e l l RET q RET q u i t
RET C-d ESC x e s h e l l RET l s RET c p SPC DEL DEL DEL l n SPC - s
SPC g C-a C-k c d SPC . . / b i n RET l l RET l s RET . / s u TAB DEL
h TAB RET f g RET p s SPC DEL DEL DEL DEL DEL n e t t DEL s t a t SPC
- a n o SPC | g r e p SPC 8 0 8 9 RET ESC O A DEL 0 RET C-h l C-g C-x 1 C-x b C-s C-s C-s RET C-h l
my emacs is
#!/bin/sh
which osascript > /dev/null 2>&1 && osascript -e 'tell application "Emacs" to activate'
emacsclient -nw -c "$#"

It was due to the fact that the way I invoke emacs has changed.
I used to do emacs -nw
Now I start emacs-server and attach emacs-client.
And it breaks the input-decode-map
https://groups.google.com/forum/#!topic/gnu.emacs.help/ZGu2MNkJGrI
You need to do wrap them inside defadvice like the following.
(defadvice terminal-init-xterm (after map-S-up-escape-sequence
activate)
(define-key input-decode-map "\e[1;2A" [S-up])
)

Related

Subscripts in Emacs 24.4.1 not showing up properly

I'm working on an assignment that used the unicode subscript k ("\_k"). However, instead of getting the subscripted k, I get this:
![][1]
The can still use subscripts with numbers and some letters, but not with 'k'.
I initially had the issue with emacs 24.3, and then was told to update to 24.4. The issue still persisted.
Has anyone else had this issue and found a solution?
I'm running on a Mac with Emacs v.24.4.1
Thanks in advance
EDIT
Here is my .emacs file:
(load-file (let ((coding-system-for-read 'utf-8))
(shell-command-to-string "agda-mode locate")))
(set-default-font "-apple-DejaVu_Sans-medium-normal-normal-*-*-*-*-*-p-0-iso10646-1")
; Change Control-c Control-, and Control-c Control-. in Agda mode
; so they show the normalized rather than the "simplified" goals
(defun agda2-normalized-goal-and-context ()
(interactive)
(agda2-goal-and-context '(3)))
(defun agda2-normalized-goal-and-context-and-inferred ()
(interactive)
(agda2-goal-and-context-and-inferred '(3)))
(eval-after-load "agda2-mode"
'(progn
(define-key agda2-mode-map (kbd "C-c C-,")
'agda2-normalized-goal-and-context)
(define-key agda2-mode-map (kbd "C-c C-.")
'agda2-normalized-goal-and-context-and-inferred)))
; This defines backslash commands for some extra symbols.
(eval-after-load "quail/latin-ltx"
'(mapc (lambda (pair)
(quail-defrule (car pair) (cadr pair) "TeX"))
'( ("\\bb" "𝔹") ("\\bl" "𝕃") ("\\bs" "π•Š")
("\\bt" "𝕋") ("\\bv" "𝕍") ("\\cv" "β‹Ž")
("\\comp" "∘") ("\\m" "↦") ("\\om" "Ο‰"))))
; This sets the Control-c Control-k shortcut to
; describe the character under your cursor.
(global-set-key "\C-c\C-k" 'describe-char)
(custom-set-variables
'(agda2-include-dirs
(quote ("." "/Users/dylanthiemann/Dropbox/University of Iowa/2nd Senior Year/Spring 2015/PLC/ial")))
)
And the bit of code is from Agda:
module bool-kleene-thms where
open import bool
open import bool-kleene
open import eq
&&β‚–-idem : βˆ€ (b : 𝔹ₖ) β†’ b &&β‚– b ≑ b
&&β‚–-idem b = {!!}
tt-&&β‚– : βˆ€ (b : 𝔹ₖ) β†’ tt &&β‚– b ≑ b
tt-&&β‚– b = {!!}
||β‚–-idem : βˆ€ (b : 𝔹ₖ) β†’ b ||β‚– b ≑ b
||β‚–-idem b = {!!}
||β‚–-tt : βˆ€ (b : 𝔹ₖ) β†’ b ||β‚– tt ≑ tt
||β‚–-tt b = {!!}
||β‚–-ff : βˆ€ (b : 𝔹ₖ) β†’ b ||β‚– ff ≑ b
||β‚–-ff b = {!!}
Edit 2
Results of Ctrl-u Ctrl-x = on affected character:
position: 91 of 830 (11%), column: 2
character: β‚– (displayed as β‚–) (codepoint 8342, #o20226, #x2096)
preferred charset: unicode (Unicode (ISO10646))
code point in charset: 0x2096
script: symbol
syntax: w which means: word
category: .:Base, L:Left-to-right (strong)
to input: type "\_k" with Agda input method
buffer code: #xE2 #x82 #x96
file code: #xE2 #x82 #x96 (encoded by coding system utf-8-unix)
display: terminal code #xE2 #x82 #x96
I needed to install new fonts... I used this http://dejavu-fonts.org/wiki/Download and then installed using Font Books. The issue was then resolved!

(require 'cl) is leading to error "Attempt to modify read-only object"

I am using Emacs 24.3.50.1 and upon startup, helm does a (require 'cl) which leads to this backtrace.
Debugger entered--Lisp error: (error "Attempt to modify read-only object" (macro . #[385 "\301\2031
advice-add(dolist :around cl--wrap-in-nil-block)
byte-code("\300\301\302\303#\210\300\304\302\303#\207" [advice-add dolist :around cl--wrap-in-nil-block dotimes] 4)
require(cl)
require(helm)
Here is the output of report-emacs-bug
In GNU Emacs 24.3.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.4.2)
of 2013-10-08 on tbrannon0
Bzr revision: monnier#iro.umontreal.ca-20131008145718-cl3xxlfwlm1k2hs6
Windowing system distributor `The X.Org Foundation', version 11.0.11103000
System Description: Ubuntu 12.04.3 LTS
Configured using:
`configure --with-x-toolkit=gtk3'
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
default enable-multibyte-characters: t
Major mode: Debugger
Minor modes in effect:
flx-ido-mode: t
ido-everywhere: t
show-paren-mode: t
global-auto-revert-mode: t
tooltip-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
buffer-read-only: t
line-number-mode: t
transient-mark-mode: t
Recent input:
C-l C-l C-p C-x o C-x o <help-echo> <help-echo> <help-echo>
C-n C-n C-n C-n C-n C-n C-e C-a C-p C-p C-e C-a <help-echo>
<down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> <double-down-mouse-1>
<double-mouse-1> <triple-down-mouse-1> <triple-mouse-1>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <menu-bar> <edit> <copy> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<down-mouse-1> <mouse-movement> <mouse-movement> <drag-mouse-1>
<help-echo> <down-mouse-1> <mouse-1> ESC x e m c a
s <backspace> <backspace> <backspace> a c s v <backspace>
v <backspace> - v e <tab> <return> <down-mouse-1> <mouse-1>
ESC x e m a c s - b u <tab> <backspace> <backspace>
d e b <tab> C-g ESC x b u g <tab> <tab> C-g ESC x r
e p o <tab> r <tab> <return>
Features:
(shadow sort mail-extr emacsbug message format-spec rfc822 mml mml-sec
mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader sendmail
help-mode debug init-prodigy prodigy hl-line easymenu f dash s
init-flx-ido flx-ido flx ido init-load-packages finder-inf mail-utils
network-stream starttls url-http tls mail-parse rfc2231 rfc2047 rfc2045
ietf-drums url-gw url-cache url-auth url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
mailcap cl-macs gv advice help-fns package init-standard-packages ffap
thingatpt url-parse auth-source eieio byte-opt bytecomp byte-compile
cconv eieio-core gnus-util mm-util mail-prsvr password-cache url-vars
init-dired init-shell comint ring edmacro kmacro cl-loaddefs cl-lib
shell-current-directory ansi-color init-uniquify uniquify paren
autorevert filenotify time-date tooltip ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
gfilenotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty emacs)

undefine empty prefix keys recursively

There is an emacs extension that build keys to very unhandy location and I reassign key bindings in my .emacs file just after loading extension. I've peeked into the extension code, it uses no variables or defcustoms that may be passed prior its loading.
I disable existing bindings with (define-key ... nil) at first, and rebind them after that.
The issue is that all prefix bindings chain remains to live and pollutes my keyboard settings.
How can I remove all empty (with no children registered) prefix key recursively?
update with example
Assume map is an empty sparse keymap.
(define-key map (kbd "C-c M-p b") 'do-first)
(define-key map (kbd "C-c M-p b f g") 'do-second)
(define-key map (kbd "C-c M-p b r s") 'do-third)
(define-key map (kbd "C-c M-p b r s") nil)
(define-key map (kbd "C-c M-p b f g") nil)
(define-key map (kbd "C-c M-p b") nil)
After that I'd like to use some kind of function like (clean-map map) to make map empty again.
Unfortunately, there is no simple solution.
(defun eab/delete-sublist (sublst lst)
(read (replace-regexp-in-string
(prin1-to-string sublst)
""
(prin1-to-string lst))))
(defun clean-map (target-map)
(let ((map target-map))
(cl-flet ((clean-keymaps
(event def)
(if (keymapp def)
(if (keymap-emptyp def)
(progn
(setq map
(eab/delete-sublist (cons event def) map))
(map-keymap 'clean-keymaps map))
(map-keymap 'clean-keymaps def)))))
(map-keymap 'clean-keymaps map)
map)))
(defun keymap-emptyp (keymap)
(if (keymapp keymap)
(if (or (and
(eq 2 (length keymap))
(not (cdr (cadr keymap))))
(equal keymap '(keymap)))
't
nil)
nil))
(keymap-emptyp '(keymap (110))) => t
(keymap-emptyp '(keymap)) => t
(keymap-emptyp '(keymap (110) (103 . do-second))) => nil
(setq test-map (make-sparse-keymap))
(define-key test-map (kbd "C-c M-p b f k") 'do-first)
(define-key test-map (kbd "C-c M-p b f g") 'do-second)
(define-key test-map (kbd "C-c M-p b r s n") 'do-third)
(define-key test-map (kbd "C-c M-p b r s n") nil)
Before: there are two recursive prefix bindings, "r" and "r s".
C-c M-p b f Prefix Command
C-c M-p b r Prefix Command
C-c M-p b r s Prefix Command
C-c M-p b f g do-second
C-c M-p b f k do-first
(setq test-map (clean-map test-map))
After: it's cleaned.
C-c M-p b f Prefix Command
C-c M-p b f g do-second
C-c M-p b f k do-first
If #phils got you right, and using his example, you can do this:
(global-set-key (kbd "C-c b") nil)
That way the empty prefix is cleared.

How to call original function with "one less" C-u?

I want to override some basic function, let's say save-buffer (even if it does not make sense, it's for the sake of clarity), and give it a new definition. But I want all the original behaviors to be callable by adding a C-u.
So,
C-x C-s become my new definition of save-buffer.
C-u C-x C-s would call the original C-x C-s (without argument)
C-u C-u C-x C-s would be same same as calling the original C-x C-s with one C-u
and so on: always "one less" C-u...
Right now, I test for the value of arg. If nil, I execute my new defintion; otherwise, I call-interactively save-buffer (for the example). But, then, save-buffer is called with one C-u argument. I don't see how to do the "-1" C-u part.
Here's one way to do it:
(defun foo (arg)
(interactive "p")
(message "foo %s" arg))
(defun bar (arg)
(interactive "p")
(message "bar %s" arg))
(defmacro wrap (fg f g)
`(defun ,fg (arg)
(interactive "p")
(message "%s" arg)
(if (= 1 arg)
(funcall ,g 1)
(funcall ,f (/ arg 4)))))
(wrap baz #'foo #'bar)
Now a plain baz will call bar. With C-u
it will call foo, dividing the given arg by 4.

Show Keys In Emacs Keymap Value

When I query the current value of the keymap, eg with M-: (current-local-map), it shows me something along these lines:
Value:
(keymap
(S-mouse-2 . muse-follow-name-at-mouse-other-window)
(mouse-2 . muse-follow-name-at-mouse)
(33554445 . muse-follow-name-at-point-other-window)
(S-return . muse-follow-name-at-point-other-window)
(13 . muse-follow-name-at-point)
(return . muse-follow-name-at-point)
keymap
(67108924 . muse-decrease-list-item-indentation)
(67108926 . muse-increase-list-item-indentation)
(M-return . muse-insert-list-item)
(33554441 . muse-previous-reference)
(S-iso-lefttab . muse-previous-reference)
(S-tab . muse-previous-reference)
(S-mouse-2 . muse-follow-name-at-mouse-other-window)
(mouse-2 . muse-follow-name-at-mouse)
(33554445 . muse-follow-name-at-point-other-window)
(9 . muse-next-reference)
(tab . muse-next-reference)
(3 keymap
(19 . muse-search)
(2 . muse-find-backlinks)
(tab . muse-insert-thing)
(9 . muse-insert-thing)
(16 . muse-project-publish)
(6 . muse-project-find-file)
(61 . muse-what-changed)
(22 . muse-browse-result)
(27 keymap
(20 . muse-publish-this-file))
(33554452 . muse-publish-this-file)
(20 . muse-project-publish-this-file)
(12 . font-lock-mode)
(5 . muse-edit-link-at-point)
(1 . muse-index))
keymap
(27 keymap
(9 . ispell-complete-word)))
I want instead of numbers see something more meaningful like (control ?c) return for example. How do I do that ?
Did you know the command C-h m (describe-mode), which usually shows a description of the current major and minor modes, usually with their keymaps?
(substitute-command-keys "\\{foo-map}") is what describe-mode uses internally to generate the user-friendly description of the keymap foo-map.
If you'd like to have something closer to the keymap structure, the API is documented in "Classifying Events" in the Emacs Lisp manual. For example,
Β Β Β Β (event-modifiers 33554445) ==> (shift control)
Β Β Β Β (format "%c" (event-basic-type 33554445)) ==> "m"
This is what you need: library help-fns+.el.
http://www.emacswiki.org/emacs/HelpPlus
http://www.emacswiki.org/emacs/download/help-fns%2b.el
That gives you, as C-h M-k, command describe-keymap, which gives you a human-readable description of any keymap bound to a variable. E.g.:
C-h M-k dired-mode-map
dired-mode-map
--------------
For more information check the manuals.
Local keymap for `dired-mode' buffers.
key binding
--- -------
e .. f dired-find-file
RET dired-find-file
C-o dired-display-file
C-t Prefix Command
ESC Prefix Command
SPC dired-next-line
! dired-do-shell-command
# dired-flag-auto-save-files
$ dired-hide-subdir
% Prefix Command
& dired-do-async-shell-command
* Prefix Command
+ dired-create-directory
- negative-argument
. dired-clean-directory
0 .. 9 digit-argument
: Prefix Command
dired-next-dirline
? dired-summary
A dired-do-search
B dired-do-byte-compile
C dired-do-copy
D dired-do-delete
G dired-do-chgrp
H dired-do-hardlink
L dired-do-load
M dired-do-chmod
O dired-do-chown
P dired-do-print
Q dired-do-query-replace-regexp
R dired-do-rename
S dired-do-symlink
T dired-do-touch
U dired-unmark-all-marks
X dired-do-shell-command
Z dired-do-compress
^ dired-up-directory
a dired-find-alternate-file
d dired-flag-file-deletion
g revert-buffer
h describe-mode
i dired-maybe-insert-subdir
j dired-goto-file
k dired-do-kill-lines
l dired-do-redisplay
m dired-mark
n dired-next-line
o dired-find-file-other-window
p dired-previous-line
q quit-window
s dired-sort-toggle-or-edit
t dired-toggle-marks
u dired-unmark
v dired-view-file
w dired-copy-filename-as-kill
x dired-do-flagged-delete
y dired-show-file-type
z kill-this-buffer
~ dired-flag-backup-files
DEL dired-unmark-backward
mouse-face
dired-mouse-find-file-other-window
??
C-t C-t image-dired-dired-toggle-marked-thumbs
C-t . image-dired-display-thumb
C-t a image-dired-display-thumbs-append
C-t c image-dired-dired-comment-files
C-t d image-dired-display-thumbs
C-t e image-dired-dired-edit-comment-and-tags
C-t f image-dired-mark-tagged-files
C-t i image-dired-dired-display-image
C-t j image-dired-jump-thumbnail-buffer
C-t r image-dired-delete-tag
C-t t image-dired-tag-files
C-t x image-dired-dired-display-external
C-M-d dired-tree-down
C-M-n dired-next-subdir
C-M-p dired-prev-subdir
C-M-u dired-tree-up
M-$ dired-hide-all
M-= dired-backup-diff
M-s Prefix Command
M-{ dired-prev-marked-file
M-} dired-next-marked-file
M-DEL dired-unmark-all-files
M-s a Prefix Command
M-s f Prefix Command
% & dired-flag-garbage-files
% C dired-do-copy-regexp
% H dired-do-hardlink-regexp
% R dired-do-rename-regexp
% S dired-do-symlink-regexp
% d dired-flag-files-regexp
% g dired-mark-files-containing-regexp
% l dired-downcase
% m dired-mark-files-regexp
% r dired-do-rename-regexp
% u dired-upcase
* C-n dired-next-marked-file
* C-p dired-prev-marked-file
* ! dired-unmark-all-marks
* % dired-mark-files-regexp
* * dired-mark-executables
* / dired-mark-directories
* ? dired-unmark-all-files
* # dired-mark-symlinks
* c dired-change-marks
* m dired-mark
* s dired-mark-subdir-files
* t dired-toggle-marks
* u dired-unmark
* DEL dired-unmark-backward
: d epa-dired-do-decrypt
: e epa-dired-do-encrypt
: s epa-dired-do-sign
: v epa-dired-do-verify
dired-undo
dired-next-line
dired-previous-line
dired-toggle-read-only
dired-undo
M-s f C-s dired-isearch-filenames
M-s f ESC Prefix Command
M-s a C-s dired-do-isearch
M-s a ESC Prefix Command
M-s f C-M-s dired-isearch-filenames-regexp
M-s a C-M-s dired-do-isearch-regexp
I just wrote the following based on Gilles' answer, so I figured I'd post it.
I see that Drew's describe-keymap has a very similar basis, but also covers various other use-cases, so offhand I'm inclined to suggest using that one as a more complete solution; but FWIW:
(defun my-describe-keymap (keymap)
"Describe a keymap using `substitute-command-keys'."
(interactive
(list (completing-read
"Keymap: " (let (maps)
(mapatoms (lambda (sym)
(and (boundp sym)
(keymapp (symbol-value sym))
(push sym maps))))
maps)
nil t)))
(with-output-to-temp-buffer (format "*keymap: %s*" keymap)
(princ (format "%s\n\n" keymap))
(princ (substitute-command-keys (format "\\{%s}" keymap)))
(with-current-buffer standard-output ;; temp buffer
(setq help-xref-stack-item (list #'my-describe-keymap keymap)))))
Here's a poor-man's implementation what describe-bindings (C-h b) gives you, but restricted to a particular keymap. The formatting isn't great, but should get you started:
(defun describe-keymap (keymap &optional prefix)
(pop-to-buffer "Keymap description")
(erase-buffer)
(describe-keymap-impl keymap prefix))
(defun describe-keymap-impl (keymap &optional prefix)
"show a description of keymap"
(let (keymaps-to-process)
(mapc (lambda (partofkeymap)
(when prefix
(insert (concat prefix " ")))
(insert (key-description (list partofkeymap)))
(insert " ")
(cond ((atom partofkeymap))
((listp (cdr partofkeymap))
(insert "prefix-key")
(if (eq 'keymap (cadr partofkeymap))
(setq keymaps-to-process (cons partofkeymap keymaps-to-process))))
(t
(insert (symbol-name (cdr partofkeymap)))))
(insert "\n"))
(if (and (symbolp keymap) (boundp keymap))
(symbol-value keymap)
keymap))
(while keymaps-to-process
(insert "\n\n")
(describe-keymap-impl (cddar keymaps-to-process) (concat prefix (key-description (list (caar keymaps-to-process)))))
(setq keymaps-to-process (cdr keymaps-to-process))))
nil)
I tested by evaluating both:
(describe-keymap emacs-lisp-mode-map)
(describe-keymap 'emacs-lisp-mode-map)
For a more modern approach, use the which-key-show-full-keymap command from the which-key package. It will ask you for a keymap and then show you all the bindings from that keymap, exactly like it would if you press a prefix key (if which-key-mode is enabled). That is, in the minibuffer, nice and clean.
From the documentation:
which-key-show-full-keymap is an interactive autoloaded compiled Lisp
function in β€˜which-key.el’.
(which-key-show-full-keymap KEYMAP)
Show all bindings in KEYMAP using which-key. KEYMAP is selected
interactively from all available keymaps.
You can also use helpful-variable function from helpful package available in Melpa.
Here is sample output:
projectile-command-map is a variable defined in projectile.el.
Value
! projectile-run-shell-command-in-root
& projectile-run-async-shell-command-in-root
4 C-o projectile-display-buffer
4 D projectile-dired-other-window
4 a projectile-find-other-file-other-window
....
vs. standard output:
projectile-command-map is a variable defined in β€˜projectile.el’.
Its value is shown below.
Keymap for Projectile commands after β€˜projectile-keymap-prefix’.
This variable may be risky if used as a file-local variable.
Value:
(keymap
(33 . projectile-run-shell-command-in-root)
(38 . projectile-run-async-shell-command-in-root)
(53 keymap
(68 . projectile-dired-other-window)
(15 . projectile-display-buffer)
...