Subject: 25.3; term-mode f-keys

From: Wenocur <[email-masked]>
Date: Sun, 31 Dec 2017 14:13:17 -0500

To trigger the problem:

Start term-mode with a visual text-mode application that requires f-keys
to function. In my case, I was using aws-shell.

Leave the terminal in char mode.

Attempt to use f-keys to operate the application.

Symptom:
The f-keys operate as they would in any other mode.

Example solution:
(defvar f-key-defs
  (let ((fkeys nil))
    (dotimes (i 12)
      (push (cons (intern (concat "f" (int-to-string (1+ i))))
                  (format "\e[%d~" (+ i (if (> i 4) 12 11))))
            fkeys))
    fkeys))

(defun send-f-key ()
  "Send an f-key escape sequence to the sub-process."
  (interactive)
  (term-send-raw-string (alist-get last-input-event f-key-defs)))

(dotimes (i 12)
  (define-key term-raw-map
    (vector (intern (concat "f" (int-to-string (1+ i)))))
    #'send-f-key))

In GNU Emacs 25.3.1 (x86_64-apple-darwin15.6.0, NS appkit-1404.47 Version 10.11.6 (Build 15G1611))
 of 2017-12-23 built on 3c0754310e53
Windowing system distributor 'Apple', version 10.3.1404
Configured features:
JPEG RSVG DBUS NOTIFY ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  diff-auto-refine-mode: t
  magit-auto-revert-mode: t
  auto-revert-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  jedi-mode: t
  auto-complete-mode: t
  TeX-PDF-mode: t
  shell-dirtrack-mode: t
  delete-selection-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-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
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Mark set
next-line: End of buffer
Mark set
Quit
scroll-up-command: End of buffer
Making completion list... [6 times]
Quit
Making completion list... [2 times]
next-line: End of buffer
Making completion list...
Quit

Load-path shadows:
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/md4 hides /Applications/Emacs.app/Contents/Resources/lisp/md4
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/hex-util hides /Applications/Emacs.app/Contents/Resources/lisp/hex-util
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/sasl hides /Applications/Emacs.app/Contents/Resources/lisp/net/sasl
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/sasl-ntlm hides /Applications/Emacs.app/Contents/Resources/lisp/net/sasl-ntlm
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/sasl-digest hides /Applications/Emacs.app/Contents/Resources/lisp/net/sasl-digest
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/sasl-cram hides /Applications/Emacs.app/Contents/Resources/lisp/net/sasl-cram
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/ntlm hides /Applications/Emacs.app/Contents/Resources/lisp/net/ntlm
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/hmac-md5 hides /Applications/Emacs.app/Contents/Resources/lisp/net/hmac-md5
/Users/wenocur/.emacs.d/elpa/flim-20161210.1728/hmac-def hides /Applications/Emacs.app/Contents/Resources/lisp/net/hmac-def
/Users/wenocur/.emacs.d/elpa/let-alist-1.0.5/let-alist hides /Applications/Emacs.app/Contents/Resources/lisp/emacs-lisp/let-alist

Features:
(shadow mail-extr emacsbug sendmail company-oddmuse company-etags
company-gtags company-dabbrev-code company-capf company-cmake
company-xcode company-semantic company-eclim company-css company-nxml
term/xterm xterm company-keywords company-files company-elisp
company-clang company-bbdb company-tests tempo ispell etags xref project
company-dabbrev company-template company enriched emu invisible inv-23
sort ess-omg-l paren ess-toolbar ess-mouse mouseme browse-url ess-swv
ess-noweb ess-bugs-l ess-sas-d ess-sas-l ess-sas-a ess-stata-mode
ess-stata-lang make-regexp essd-els ess-sp6-d ess-dde ess-sp3-d
ess-julia julia-mode ess-r-mode ess-r-package ess-r-syntax
ess-r-completion ess-roxy essddr ess-rd hideshow ess-s-lang ess-help
ess-site ess ess-mode ess-noweb-mode ess-inf ess-tracebug ess-generics
ess-utils ess-custom ess-compat ess-lsp-l ntlm hex-util hmac-md5 sasl
sasl-anonymous sasl-login sasl-plain md4 mmbuffer hmac-def poem poem-e20
poem-e20_3 mmgeneric help-macro iedit-lib rect magit-obsolete
magit-notes magit-worktree magit-branch magit-collab ghub let-alist
magit-files magit-refs magit-status dired-x magit-repos epa magit-margin
ido recentf tree-widget color gud noutline outline w3m-rss w3m doc-view
image-mode w3m-hist w3m-fb bookmark-w3m w3m-ems w3m-ccl w3m-favicon
w3m-image w3m-proc w3m-util mime eword-decode mel path-util mime-parse
std11 luna mime-def mcharset mcs-20 mcs-e20 pces pces-e20 pces-20
pcustom pccl pccl-20 ccl broken poe calist esh-var esh-io esh-cmd
esh-opt esh-ext esh-proc esh-arg esh-groups eshell esh-module esh-mode
esh-util conf-mode magit-ediff ediff-merg ediff-wind ediff-diff
ediff-mult ediff-help ediff-init ediff-util ediff alist pym static
apel-ver product jka-compr descr-text ielm novice eieio-opt speedbar
sb-image ezimage dframe two-column eterm-256color subr-x f xterm-color s
tmm face-remap tramp-cache sh-script smie executable js sgml-mode
thingatpt cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs vc-git flymake linum magit-blame magit-stash
magit-bisect magit-remote magit-commit magit-sequence magit magit-apply
magit-wip magit-log magit-diff smerge-mode diff-mode magit-core
magit-autorevert autorevert filenotify magit-process magit-popup
magit-mode magit-git magit-section magit-utils git-commit log-edit
pcvs-util add-log with-editor async-bytecomp async server dash
pcmpl-unix imenu man jedi jedi-core python-environment epc ctable
concurrent deferred auto-complete popup pyvenv python tramp-sh tramp
tramp-compat tramp-loaddefs trampver json map lua-mode preview tex-jp
ert find-func ewoc debug timezone texinfo toolbar-x prv-emacs reporter
desktop frameset context plain-tex tex-buf latex tex-ispell tex-style
tex easy-mmode dbus xml crm warnings tex-site advice derived rx cl
compile autoload lisp-mnt tar-mode mm-archive message dired format-spec
rfc822 mml mml-sec epg mailabbrev gmm-utils mailheader mm-decode
mm-bodies mm-encode url-handlers mail-utils pp cus-edit cus-start
cus-load wid-edit network-stream nsm starttls url-http tls gnutls
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 url-parse auth-source cl-seq eieio eieio-core
gnus-util mm-util help-fns mail-prsvr password-cache url-vars mailcap
misearch multi-isearch term disp-table ehelp shell pcomplete comint
ansi-color ring cl-macs edmacro kmacro delsel finder-inf info package
epg-config seq byte-opt gv bytecomp byte-compile cl-extra help-mode
easymenu cconv cl-loaddefs pcase cl-lib time-date mule-util tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
ns-win ucs-normalize term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cl-generic cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded 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 dbusbind kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 1114929 884507)
 (symbols 48 76240 45)
 (miscs 40 663 3464)
 (strings 32 270981 56813)
 (string-bytes 1 6199772)
 (vectors 16 82065)
 (vector-slots 8 2098783 180474)
 (floats 8 805 2294)
 (intervals 56 20421 56971)
 (buffers 976 62))