summaryrefslogtreecommitdiff
path: root/itches/emacs/interpreters.org
blob: 535405d527c92d7138b675e8e57d627670a46a62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
* Shell
** Add faces instead of reusing font-lock-{comment,string}
** Improve directory tracking
Ensure ~default-directory~ remains consistent with the shell's current
working directory.  Some things ~shell-mode~ does not handle:

- ~autocd~ (there's ~shell-has-auto-cd~, but it does not track whether
  ~autocd~ is *actually* set)
- ~cd !$~
- ~ssh~
- Docker containers

Some solutions:
- Emacs 28's ~comint-osc-process-output~
  - requires configuring the prompt
  - does not handle SSH (yet)
  - relies on OSC 7, which is [[https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20][not standard yet]]
- running this clumsy thing after every command:
  #+begin_src sh
  (file-truename
   (format "/proc/%d/cwd"
           (process-id (get-buffer-process (current-buffer)))))
  #+end_src

** Use Bash completions
Emacs filename completions in =*shell*= are subtly different to
Bash's; e.g. typing ~ls TAB~ in a folder with a single file expands to
~ls that-file~.

Also, in general, =*shell*= has no clue about

- changes to =$PATH=, which affect what programs are available,
- Bash aliases,
- changes to the current working directory not triggered by an
  explicit ~cd~, and not announced by OSC 7,
- etc.

See [[https://debbugs.gnu.org/26661][bug#26661]], and [[https://github.com/szermatt/emacs-bash-completion/issues/45][szermatt/emacs-bash-completion!45]].
** Handle DECSC, DECRC, CUU, ED, HVP and DECSTBM console codes
Used for APT's "Dpkg::Progress-Fancy" option, enabled by default with
the high-level apt(8) command.  Silly script emulating what APT does:
#+begin_src bash
#!/bin/bash

set -eu

if ! test "${LINES:-}" -a "${COLUMNS:-}"
then
    echo Please export LINES and COLUMNS.
    exit 1
fi

# Adapted from apt/apt-pkg/install-progress.cc.

backup=$'\e7'                    # DECSC: backup cursor position.
restore=$'\e8'                   # DECRC: restore cursor position.

setup ()
{
    echo -n ${backup}
    # DECSTBM: restrict scrolling below command, and above progress
    #          bar.  Side-effect: move the cursor to position 1:1,
    #          hence the backup/restore.
    echo -n $'\e[0;'$((LINES-1))'r'
    echo -n ${restore}
}

teardown ()
{
    # ED: clear everything from current position to end of screen.
    #     Dixit Michael Vogt: "sledgehammer".
    echo -n $'\e[J'
}

# APT surrounds this setup phase with \n and \e[1A (CUU).  I don't
# know why; the comments say that this is to "avoid visual glitch when
# the screen area shrinks by one row".  No further explanation is
# given in commit messages.
setup

for ((i=1;i<COLUMNS-1;i++))
do
    if ! ((i%10))
    then
        echo "installing stuff"
    fi

    echo -n ${backup}

    # HVP: move cursor to last line, first column.
    echo -n $'\e['${LINES}';1f'

    # Draw progress bar.
    progress='['
    for ((j=1;j<=i;j++))
    do
        progress+='#'
    done
    for ((j=i+1;j<COLUMNS-1;j++))
    do
        progress+='.'
    done
    progress+=']'
    echo -n ${progress}

    echo -n ${restore}

    sleep 0.1
done

teardown
#+end_src

* Eshell
** ~ls --group-directories-first~ does not color folders
* Python shell
** Handle ~completion-prefix-display-length~
Setting this variable in an inputrc file causes the Python interpreter
to elide common prefixes when showing completion candidates.  This
seems to confuse python-shell-completion-native-get-completions (at
best hitting TAB yields "No match", at worst it makes Emacs hang).