Subject: bug#69114: 29.1; OSC7 directory tracking sometimes fails on Mac OSX (needs workaround?)

From: Brian Marick <[email-masked]>
Date: Tue, 13 Feb 2024 18:19:35 -0600

I use OSC7 directory tracking with (add-hook
'comint-output-filter-functions #'comint-osc-process-output)

This works when I am on my home wifi, or with wifi turned off, or when
tethered to my phone. It does *not* work when (I think) reverse-DNS
lookup assigns my machine someone else's old name.

My directory tracking OSCX7 output looks like this:

    file://ebenezer2023.local/Users/bem

The hostname is always the same. (Right now, it's hardcoded.)

In the working situations, the bash `$HOSTNAME` is
`ebenezer2023.local`. `scutil --get ComputerName` returns
`ebenezer2023`. (These are all correct.)

But in this one particular location, with their particular wifi setup,
if I create a shell buffer, the hostname is (I'm guessing) from some
leftover IP address. At this moment $HOSTNAME is `DESKTOP-TEBA9J7`. `scutil`
produces the same correct output (`ebenezer2023`) as before, but it doesn't matter. Directory
tracking stops working.

My hunch is that the OS is being told about a `file:` on
`ebenezer2023.local`, says "I am `DESKTOP-TEBA9J7`. I know nothing of
this 'ebenezer'. Therefore, I shall fail.” 

This is clearly (to me) a problem with MacOSX. However, I haven't been
able to find a workaround. (For example, I'd hoped that somehow,
magically, starting a shell with wifi off, then it would work with wifi on, but no.)

I don't know if there's anything you can do, or if you can supply any
workaround.

Note: I've tried leaving the hostname empty (`file:///Users...`) and
putting `localhost` in it, but no joy.

I also described this in `https://emacs.stackexchange.com/questions/80343/comint-osc-process-output-directory-tracking-does-not-seem-to-allow-an-empty-hos` <https://emacs.stackexchange.com/questions/80343/comint-osc-process-output-directory-tracking-does-not-seem-to-allow-an-empty-hos%60> which got this response, which may be helpful:

"Arguably it is a bug. The function ansi-osc-directory-tracker in Emacs expects the host part of the url to be nil if it was left unspecified, but the function which actually parses urls (url-generic-parse-url) sets it to the empty string instead. It does set the port to nil if it is an empty string, but it doesn’t do that for the host.

"Which one is wrong? It is hard to say. But you could use M-x report-emacs-bug to send an email to the developers with that information and let them hash it out. In the mean time fixing your prompt as you have done is the right thing to do.”

[The last sentence was before I realized my fix didn’t actually fix the problem.)

In GNU Emacs 29.1 (build 1, aarch64-apple-darwin21.6.0, NS
appkit-2113.60 Version 12.6.6 (Build 21G646)) of 2023-08-16 built on
armbob.lan
Windowing system distributor 'Apple', version 10.3.2487
System Description:  macOS 14.2.1

Configured using:
'configure --with-ns '--enable-locallisppath=/Library/Application
Support/Emacs/${version}/site-lisp:/Library/Application
Support/Emacs/site-lisp' --with-modules 'CFLAGS=-DFD_SETSIZE=10000
-DDARWIN_UNLIMITED_SELECT' --with-x-toolkit=no'

Configured features:
ACL GLIB GMP GNUTLS JPEG JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER
PNG RSVG SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER ZLIB

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

Major mode: Shell

Minor modes in effect:
  recentf-mode: t
  auto-dim-other-buffers-mode: t
  server-mode: t
  windmove-mode: t
  global-auto-revert-mode: t
  save-place-mode: t
  counsel-mode: t
  comint-fontify-input-mode: t
  ivy-mode: t
  delete-selection-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/Users/bem/.emacs.d/elpa/transient-20240114.1722/transient hides /Applications/Emacs.app/Contents/Resources/lisp/transient
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-jump hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-jump
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-ensure hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-ensure
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-core hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-core
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-delight hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-delight
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-diminish hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-diminish
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-bind-key hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-bind-key
/Users/bem/.emacs.d/elpa/bind-key-20160227.48/bind-key hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/bind-key
/Users/bem/.emacs.d/elpa/use-package-20210207.1926/use-package-lint hides /Applications/Emacs.app/Contents/Resources/lisp/use-package/use-package-lint
/Users/bem/.emacs.d/elpa/seq-2.24/seq hides /Applications/Emacs.app/Contents/Resources/lisp/emacs-lisp/seq

Features:
(shadow sort mail-extr emacsbug message yank-media puny rfc822 mml
mml-sec epa epg rfc6068 epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils jka-compr
multiple-cursors-core rect pcmpl-unix edmacro kmacro time-date files-x
shell pcomplete smex ido sh-script smie executable vc-git diff-mode
easy-mmode vc-dispatcher recentf tree-widget wid-edit bookmark hl-line
hl-sexp auto-dim-other-buffers face-remap wheatgrass-theme server
marick-elixir mix use-package-core eglot external-completion array
jsonrpc ert pp ewoc debug backtrace find-func flymake-proc flymake
warnings icons imenu windmove god-mode browse-kill-ring autorevert
filenotify exec-path-from-shell dedicate-windows-manually checkdoc
lisp-mnt thingatpt saveplace midnight misc cl counsel xdg xref project
dired dired-loaddefs compile text-property-search comint ansi-osc
ansi-color swiper cl-extra help-mode ivy delsel ring ivy-faces
ivy-overlay colir color elixir-ts-mode heex-ts-mode derived pcase rx
treesit auto-dim-other-buffers-autoloads counsel-autoloads
exunit-autoloads flycheck-eglot-autoloads god-mode-autoloads advice
company-autoloads mix-autoloads mixed-pitch-autoloads
smartparens-autoloads swiper-autoloads ivy-autoloads transient-autoloads
compat-autoloads seq-autoloads info package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs password-cache json subr-x
map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine 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
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 187383 14485)
(symbols 48 17521 0)
(strings 32 56662 2548)
(string-bytes 1 1733076)
(vectors 16 33014)
(vector-slots 8 420859 15967)
(floats 8 171 383)
(intervals 56 3176 1361)
(buffers 984 17))