unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
@ 2022-09-15  8:24 Matthias Meulien
  2022-09-15 11:13 ` Matthias Meulien
  0 siblings, 1 reply; 21+ messages in thread
From: Matthias Meulien @ 2022-09-15  8:24 UTC (permalink / raw)
  To: 57821

[-- Attachment #1: Type: text/plain, Size: 626 bytes --]


Under the hypothesis of a host with Python installed with poetry,
pre-commit tooling and flatpak builder:

1. Start 'emacs -Q'

2. Clone the Git repository https://github.com/orontee/argos and install
   pre-commit hooks as described in the CONTRIBUTING guide

3. Visit a file in the directory containing the cloned repository

3. C-x p c poetry run pre-commit run -a RET

4. Rename buffer (C-x x u)

5. C-x p c flatpak-builder --user --install --force-clean builddir
   io.github.orontee.Argos.json

Observe that the first compilationbuffer doesn't show any ANSI sequences
but the second displays many ^G^[ char sequences:


[-- Attachment #2: Capture d’écran du 2022-09-15 08-57-08.png --]
[-- Type: image/png, Size: 224441 bytes --]

[-- Attachment #3: Type: text/plain, Size: 102 bytes --]


With `ansi-color-compilation-filter' added to `compilation-filter-hook',
the situation is the same:


[-- Attachment #4: Capture d’écran du 2022-09-15 08-52-35.png --]
[-- Type: image/png, Size: 280247 bytes --]

[-- Attachment #5: Type: text/plain, Size: 252 bytes --]


Again same situation when running both commands from a shell buffer.

But with `comint-osc-process-output' added to
`comint-output-filter-functions' then everything looks good.  It seems
that flatpak-builder outputs OSC sequences and ANSI sequences.


[-- Attachment #6: Capture d’écran du 2022-09-15 10-23-38.png --]
[-- Type: image/png, Size: 323661 bytes --]

[-- Attachment #7: Type: text/plain, Size: 6891 bytes --]


Is there a way to filter out (or render) OSC sequences from compilation
output buffers as is possible for comint output?



In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, cairo version
 1.16.0) of 2022-09-14 built on carbon
Repository revision: f0798ac13dcb4c01a883f165e03c3cd7f208667c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-native-compilation --with-x-toolkit=no'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY OLDXMENU PDUMPER PNG RSVG SECCOMP SOUND
SQLITE3 THREADS TIFF WEBP X11 XDBE XIM XINPUT2 XPM ZLIB

Important settings:
  value of $LANG: fr_FR.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Bookmark Menu

Minor modes in effect:
  shell-dirtrack-mode: t
  hl-line-mode: t
  header-line-indent-mode: t
  highlight-changes-visible-mode: t
  minions-mode: t
  global-company-mode: t
  company-mode: t
  desktop-save-mode: t
  pixel-scroll-precision-mode: t
  save-place-mode: t
  electric-pair-mode: t
  icomplete-mode: t
  global-so-long-mode: t
  global-auto-revert-mode: t
  auto-insert-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-layout-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  window-divider-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/matthias/.config/emacs/elpa/dictionary-20201001.1727/dictionary hides /usr/local/share/emacs/29.0.50/lisp/net/dictionary

Features:
(shadow sort gnus-cite mail-extr emacsbug cl-print gnus-async qp gnus-ml
disp-table gnus-topic nndraft nnmh nnfolder utf-7 epa-file gnus-agent
gnus-srvr gnus-score score-mode nnvirtual gnus-msg gnus-cache generic po
pcmpl-unix sh-script executable git-link meson-mode smie shell pulse
files-x grep rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid nxml-mode
nxml-outln nxml-rap sgml-mode facemenu shortdoc help-fns radix-tree
hideshow cap-words superword subword js restclient ox-odt rng-loc
rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns
nxml-enc xmltok nxml-util ox-latex ox-icalendar org-agenda ox-html table
ox-ascii ox-publish ox org-element avl-tree ol-eww ol-rmail ol-mhe
ol-irc ol-info ol-gnus nnselect gnus-art mm-uu mml2015 mm-view mml-smime
smime dig ol-docview doc-view jka-compr ol-bibtex ol-bbdb ol-w3m ol-doi
org-link-doi mm-archive mule-util gnutls network-stream url-cache
url-http url-auth url-gw nsm finder-inf misearch multi-isearch
emacs-news-mode image-dired image-dired-tags image-dired-external
image-dired-util wallpaper image-mode exif gnus-sum man eww xdg
url-queue shr pixel-fill kinsoku url-file svg dom mm-url hl-line dabbrev
log-edit add-log smerge-mode diff whitespace display-line-numbers
hilit-chg dired-aux flyspell goto-addr rst vc-hg vc-bzr vc-src vc-sccs
vc-svn vc-cvs vc-rcs log-view pcvs-util vc-dir vc go-mode ffap eglot
array jsonrpc ert ewoc debug backtrace flymake-proc flymake compile
imenu company-oddmuse company-keywords company-etags etags fileloop
generator xref company-gtags company-dabbrev-code company-dabbrev
company-files company-clang company-capf company-cmake company-semantic
company-template company-bbdb ob-python python project minions compat
company pcase carbon-custom cus-edit cus-load gnus-demon nntp gnus-group
gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap nnmail
mail-source utf7 parse-time gnus-spec gnus-win nnoo gnus-int gnus-range
message sendmail yank-media puny rfc822 mml mml-sec epa derived epg
rfc6068 epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231
rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus nnheader
gnus-util mail-utils range mm-util mail-prsvr wid-edit gnus-dired
dired-x dired dired-loaddefs org-capture org-refile org ob ob-tangle
ob-ref ob-lob ob-table ob-exp org-macro org-footnote org-src ob-comint
org-pcomplete pcomplete comint ansi-color org-list org-faces
org-entities org-version ob-emacs-lisp ob-core ob-eval org-table
oc-basic bibtex iso8601 ol org-keys oc org-compat org-macs org-loaddefs
format-spec find-func cal-menu calendar cal-loaddefs dictionary link
connection advice markdown-mode color thingatpt noutline outline
skeleton find-file vc-git diff-mode easy-mmode vc-dispatcher ispell
time-date comp comp-cstr warnings icons rx cl-extra help-mode desktop
frameset server bookmark text-property-search pp pixel-scroll cua-base
ring saveplace elec-pair icomplete so-long autorevert filenotify
autoinsert cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs generic-x face-remap
graphviz-dot-mode-autoloads lsp-pyright-autoloads lsp-mode-autoloads
ht-autoloads f-autoloads lv-autoloads proof-site proof-autoloads
s-autoloads spinner-autoloads info yaml-autoloads 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 cconv url-vars cl-loaddefs cl-lib
rmc iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
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 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 dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo xinput2 x
multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 949696 128038)
 (symbols 48 46759 4)
 (strings 32 251243 27013)
 (string-bytes 1 10003438)
 (vectors 16 97565)
 (vector-slots 8 2088345 194542)
 (floats 8 651 694)
 (intervals 56 24377 3352)
 (buffers 1000 98))

-- 
Matthias

^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-15  8:24 bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer Matthias Meulien
@ 2022-09-15 11:13 ` Matthias Meulien
  2022-09-16 11:20   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 21+ messages in thread
From: Matthias Meulien @ 2022-09-15 11:13 UTC (permalink / raw)
  To: 57821

Matthias Meulien <orontee@gmail.com> writes:

> (...) But with `comint-osc-process-output' added to
> `comint-output-filter-functions' then everything looks good.  It seems
> that flatpak-builder outputs OSC sequences and ANSI sequences.

The OSC sequences sent by flatpak-builder are meant to update the window
title (See https://terminalguide.namepad.de/seq/osc-2/).  I plan to
provide an osc-compilation-filter (modelled on
ansi-color-compilation-filter) to be added to compilation-filter-hook.

One possible mode is to filter out all osc sequences.  An other mode
would be to call per command handlers as done by
comint-osc-process-output.

Any thought?

-- 
Matthias





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-15 11:13 ` Matthias Meulien
@ 2022-09-16 11:20   ` Lars Ingebrigtsen
  2022-09-16 20:59     ` Matthias Meulien
  2022-09-17 17:21     ` Matthias Meulien
  0 siblings, 2 replies; 21+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-16 11:20 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821

Matthias Meulien <orontee@gmail.com> writes:

> The OSC sequences sent by flatpak-builder are meant to update the window
> title (See https://terminalguide.namepad.de/seq/osc-2/).  I plan to
> provide an osc-compilation-filter (modelled on
> ansi-color-compilation-filter) to be added to compilation-filter-hook.
>
> One possible mode is to filter out all osc sequences.  An other mode
> would be to call per command handlers as done by
> comint-osc-process-output.
>
> Any thought?

The default could be to filter out all unknown OSC sequences?





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-16 11:20   ` Lars Ingebrigtsen
@ 2022-09-16 20:59     ` Matthias Meulien
  2022-09-17 17:21     ` Matthias Meulien
  1 sibling, 0 replies; 21+ messages in thread
From: Matthias Meulien @ 2022-09-16 20:59 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 57821

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Matthias Meulien <orontee@gmail.com> writes:
>
>> The OSC sequences sent by flatpak-builder are meant to update the window
>> title (See https://terminalguide.namepad.de/seq/osc-2/).  I plan to
>> provide an osc-compilation-filter (modelled on
>> ansi-color-compilation-filter) to be added to compilation-filter-hook.
>>
>> One possible mode is to filter out all osc sequences.  An other mode
>> would be to call per command handlers as done by
>> comint-osc-process-output.
>>
>> Any thought?
>
> The default could be to filter out all unknown OSC sequences?

Yes.  The following already achieves this:

(defconst osc-control-seq-regexp
  ;; See ECMA 48, section 8.3.89 "OSC - OPERATING SYSTEM COMMAND".
  "\e\\][\x08-\x0D]*[\x20-\x7E]*\\(\a\\|\e\\\\\\)"
  "Regexp matching an OSC control sequence.")

(defun osc-filter-region (begin end)
  "Filter out all OSC control sequences from region BEGIN to END."
  (save-excursion
    (goto-char begin)
    ;; Delete escape sequences.
    (while (re-search-forward osc-control-seq-regexp end t)
      (delete-region (match-beginning 0) (match-end 0)))))

(defun osc-compilation-filter ()
  (let ((inhibit-read-only t))
    (osc-filter-region compilation-filter-start (point))))

(add-hook 'compilation-filter-hook #'osc-compilation-filter)


I'll try to implement the `osc-compilation-filter' this week-end.  What
would be the right place for this, progmodes/compile.el?  A new osc.el
file?

Side notes:

1. I just learnt about the optional COMINT argument of `compile': It
solves the original problem of filtering OSC sequences from compilation
output buffers; One has to add `comint-osc-process-output' to
`comint-output-filter-functions' and then must call `compile' with
universal argument...

2. With the patch attached to bug#57866 installed, OSC 2 sequences are
collected from comint buffers and the frame title can be updated.
-- 
Matthias





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-16 11:20   ` Lars Ingebrigtsen
  2022-09-16 20:59     ` Matthias Meulien
@ 2022-09-17 17:21     ` Matthias Meulien
  2022-09-18 10:33       ` Lars Ingebrigtsen
  1 sibling, 1 reply; 21+ messages in thread
From: Matthias Meulien @ 2022-09-17 17:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 57821

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Matthias Meulien <orontee@gmail.com> writes:
>
>> The OSC sequences sent by flatpak-builder are meant to update the window
>> title (See https://terminalguide.namepad.de/seq/osc-2/).  I plan to
>> provide an osc-compilation-filter (modelled on
>> ansi-color-compilation-filter) to be added to compilation-filter-hook.
>>
>> One possible mode is to filter out all osc sequences.  An other mode
>> would be to call per command handlers as done by
>> comint-osc-process-output.
>>
>> Any thought?
>
> The default could be to filter out all unknown OSC sequences?

Here are three patchs that:
- Extract current support of OSC escape sequences from comint.el
- Handle OSC command to set window title
- Provide an OSC escape sequences filter for compilation buffer


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Extract-support-of-OSC-escape-sequences-from-comint.patch --]
[-- Type: text/x-diff, Size: 13176 bytes --]

From 792e592e423359f43e8420eb674ccfb328f74a2b Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sat, 17 Sep 2022 11:45:33 +0200
Subject: [PATCH 1/3] Extract support of OSC escape sequences from comint

* lisp/comint.el (ansi-color):
(comint-osc-handlers):
(comint-osc--marker):
(comint-osc-directory-tracker):
(comint-osc-hyperlink-handler):
(comint-osc-button-type):
(comint-osc-hyperlink-map):
(comint-osc-process-output):
(url-host):
(url-type):
(url-filename):
(comint-osc-hyperlink):
(comint-osc-hyperlink--state):
* lisp/osc.el (osc-handlers):
(osc--marker):
(osc-apply-region):
(url-host):
(url-type):
(url-filename):
(osc-directory-tracker):
(osc-hyperlink-map):
(osc-hyperlink):
(osc-hyperlink--state):
(osc-hyperlink-handler):
(osc):
---
 lisp/comint.el         |  91 ++++-------------------------
 lisp/osc.el            | 127 +++++++++++++++++++++++++++++++++++++++++
 test/lisp/osc-tests.el |  57 ++++++++++++++++++
 3 files changed, 194 insertions(+), 81 deletions(-)
 create mode 100644 lisp/osc.el
 create mode 100644 test/lisp/osc-tests.el

diff --git a/lisp/comint.el b/lisp/comint.el
index 696dac3d12..71ccbfc4e0 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -103,6 +103,7 @@
 
 (require 'ring)
 (require 'ansi-color)
+(require 'osc)
 (require 'regexp-opt)                   ;For regexp-opt-charset.
 (eval-when-compile (require 'subr-x))
 \f
@@ -3914,12 +3915,11 @@ comint-redirect-results-list-from-process
 ;; to `comint-osc-handlers' allows a customized treatment of further
 ;; sequences.
 
-(defvar-local comint-osc-handlers '(("7" . comint-osc-directory-tracker)
-                                    ("8" . comint-osc-hyperlink-handler))
-  "Alist of handlers for OSC escape sequences.
-See `comint-osc-process-output' for details.")
-
-(defvar-local comint-osc--marker nil)
+;; Aliases defined for reverse compatibility
+(defalias 'comint-osc-directory-tracker 'osc-directory-tracker)
+(defalias 'comint-osc-hyperlink-handler 'osc-hyperlink-handler)
+(defalias 'comint-osc-button-type 'osc-button-type)
+(defalias 'comint-osc-hyperlink-map 'osc-hyperlink-map)
 
 (defun comint-osc-process-output (_)
   "Interpret OSC escape sequences in comint output.
@@ -3935,81 +3935,10 @@ comint-osc-process-output
 `comint-osc-handlers' alist, the corresponding value, which
 should be a function, is called with `command' and `text' as
 arguments, with point where the escape sequence was located."
-  (let ((bound (process-mark (get-buffer-process (current-buffer)))))
-    (save-excursion
-      ;; Start one char before last output to catch a possibly stray ESC
-      (goto-char (or comint-osc--marker (1- comint-last-output-start)))
-      (when (eq (char-before) ?\e) (backward-char))
-      (while (re-search-forward "\e]" bound t)
-        (let ((pos0 (match-beginning 0))
-              (code (and (re-search-forward "\\=\\([0-9A-Za-z]*\\);" bound t)
-                         (match-string 1)))
-              (pos1 (point)))
-          (if (re-search-forward "\a\\|\e\\\\" bound t)
-              (let ((text (buffer-substring-no-properties
-                           pos1 (match-beginning 0))))
-                (setq comint-osc--marker nil)
-                (delete-region pos0 (point))
-                (when-let ((fun (cdr (assoc-string code comint-osc-handlers))))
-                  (funcall fun code text)))
-            (put-text-property pos0 bound 'invisible t)
-            (setq comint-osc--marker (copy-marker pos0))))))))
-
-;; Current directory tracking (OSC 7)
-
-(declare-function url-host "url/url-parse.el")
-(declare-function url-type "url/url-parse.el")
-(declare-function url-filename "url/url-parse.el")
-(defun comint-osc-directory-tracker (_ text)
-  "Update `default-directory' from OSC 7 escape sequences.
-
-This function is intended to be included as an entry of
-`comint-osc-handlers'.  You should moreover arrange for your
-shell to print the appropriate escape sequence at each prompt,
-say with the following command:
-
-    printf \"\\e]7;file://%s%s\\e\\\\\" \"$HOSTNAME\" \"$PWD\"
-
-This functionality serves as an alternative to `dirtrack-mode'
-and `shell-dirtrack-mode'."
-  (let ((url (url-generic-parse-url text)))
-    (when (and (string= (url-type url) "file")
-               (or (null (url-host url))
-                   (string= (url-host url) (system-name))))
-      (ignore-errors
-        (cd-absolute (url-unhex-string (url-filename url)))))))
-
-;; Hyperlink handling (OSC 8)
-
-(defvar comint-osc-hyperlink-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-c\r" 'browse-url-button-open)
-    (define-key map [mouse-2] 'browse-url-button-open)
-    (define-key map [follow-link] 'mouse-face)
-    map)
-  "Keymap used by OSC 8 hyperlink buttons.")
-
-(define-button-type 'comint-osc-hyperlink
-  'keymap comint-osc-hyperlink-map
-  'help-echo (lambda (_ buffer pos)
-               (when-let ((url (get-text-property pos 'browse-url-data buffer)))
-                 (format "mouse-2, C-c RET: Open %s" url))))
-
-(defvar-local comint-osc-hyperlink--state nil)
-
-(defun comint-osc-hyperlink-handler (_ text)
-  "Create a hyperlink from an OSC 8 escape sequence.
-This function is intended to be included as an entry of
-`comint-osc-handlers'."
-  (when comint-osc-hyperlink--state
-    (let ((start (car comint-osc-hyperlink--state))
-          (url (cdr comint-osc-hyperlink--state)))
-      (make-text-button start (point)
-                        'type 'comint-osc-hyperlink
-                        'browse-url-data url)))
-  (setq comint-osc-hyperlink--state
-        (and (string-match ";\\(.+\\)" text)
-             (cons (point-marker) (match-string-no-properties 1 text)))))
+  (let ((start (1- comint-last-output-start))
+        ;; Start one char before last output to catch a possibly stray ESC
+        (bound (process-mark (get-buffer-process (current-buffer)))))
+    (osc-apply-on-region start bound)))
 
 \f
 ;;; Input fontification and indentation through an indirect buffer
diff --git a/lisp/osc.el b/lisp/osc.el
new file mode 100644
index 0000000000..224981a856
--- /dev/null
+++ b/lisp/osc.el
@@ -0,0 +1,127 @@
+;;; osc.el --- Support for OSC escape sequences      -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022  Free Software Foundation, Inc.
+
+;; Author: Augusto Stoffel <arstoffel@gmail.com>
+;;         Matthias Meulien <orontee@gmail.com>
+;; Maintainer: emacs-devel@gnu.org
+;; Keywords: processes, terminals, services
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Interpretation of OSC (Operating System Commands) escape
+;; sequences. Handlers for OSC 7 and 8 (for current directory and
+;; hyperlinks respectively) are provided.
+
+;;; Code:
+
+(defvar-local osc-handlers '(("7" . osc-directory-tracker)
+                             ("8" . osc-hyperlink-handler))
+  "Alist of handlers for OSC escape sequences.
+See `osc-apply-on-region' for details.")
+
+(defvar-local osc--marker nil)
+;; The function `osc-apply-on-region' can set `osc--marker' to the start
+;; position of an escape sequence without termination.
+
+(defun osc-apply-on-region (begin end)
+  "Interpret OSC escape sequences in region.
+This function search for escape sequences of the forms
+
+    ESC ] command ; text BEL
+    ESC ] command ; text ESC \\
+
+Every occurrence of such escape sequences is removed from the
+buffer.  Then, if `command' is a key of the local variable
+`osc-handlers' alist, the corresponding value, which should be a
+function, is called with `command' and `text' as arguments, with
+point where the escape sequence was located."
+  (save-excursion
+    (goto-char (or osc--marker begin))
+    (when (eq (char-before) ?\e) (backward-char))
+    (while (re-search-forward "\e]" end t)
+      (let ((pos0 (match-beginning 0))
+            (code (and (re-search-forward "\\=\\([0-9A-Za-z]*\\);" end t)
+                       (match-string 1)))
+            (pos1 (point)))
+        (if (re-search-forward "\a\\|\e\\\\" end t)
+            (let ((text (buffer-substring-no-properties
+                         pos1 (match-beginning 0))))
+              (setq osc--marker nil)
+              (delete-region pos0 (point))
+              (when-let ((fun (cdr (assoc-string code osc-handlers))))
+                (funcall fun code text)))
+          (put-text-property pos0 end 'invisible t)
+          (setq osc--marker (copy-marker pos0)))))))
+
+;; Current directory tracking (OSC 7)
+
+(declare-function url-host "url/url-parse.el")
+(declare-function url-type "url/url-parse.el")
+(declare-function url-filename "url/url-parse.el")
+(defun osc-directory-tracker (_ text)
+  "Update `default-directory' from OSC 7 escape sequences.
+
+This function is intended to be included as an entry of
+`osc-handlers'.  You should moreover arrange for your shell to
+print the appropriate escape sequence at each prompt, say with
+the following command:
+
+    printf \"\\e]7;file://%s%s\\e\\\\\" \"$HOSTNAME\" \"$PWD\"
+
+This functionality serves as an alternative to `dirtrack-mode'
+and `shell-dirtrack-mode'."
+  (let ((url (url-generic-parse-url text)))
+    (when (and (string= (url-type url) "file")
+               (or (null (url-host url))
+                   (string= (url-host url) (system-name))))
+      (ignore-errors
+        (cd-absolute (url-unhex-string (url-filename url)))))))
+
+;; Hyperlink handling (OSC 8)
+
+(defvar osc-hyperlink-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\r" 'browse-url-button-open)
+    (define-key map [mouse-2] 'browse-url-button-open)
+    (define-key map [follow-link] 'mouse-face)
+    map)
+  "Keymap used by OSC 8 hyperlink buttons.")
+
+(define-button-type 'osc-hyperlink
+  'keymap osc-hyperlink-map
+  'help-echo (lambda (_ buffer pos)
+               (when-let ((url (get-text-property pos 'browse-url-data buffer)))
+                 (format "mouse-2, C-c RET: Open %s" url))))
+
+(defvar-local osc-hyperlink--state nil)
+
+(defun osc-hyperlink-handler (_ text)
+  "Create a hyperlink from an OSC 8 escape sequence.
+This function is intended to be included as an entry of
+`osc-handlers'."
+  (when osc-hyperlink--state
+    (let ((start (car osc-hyperlink--state))
+          (url (cdr osc-hyperlink--state)))
+      (make-text-button start (point)
+                        'type 'osc-hyperlink
+                        'browse-url-data url)))
+  (setq osc-hyperlink--state
+        (and (string-match ";\\(.+\\)" text)
+             (cons (point-marker) (match-string-no-properties 1 text)))))
+
+(provide 'osc)
+;;; osc.el ends here
diff --git a/test/lisp/osc-tests.el b/test/lisp/osc-tests.el
new file mode 100644
index 0000000000..d53bab08d3
--- /dev/null
+++ b/test/lisp/osc-tests.el
@@ -0,0 +1,57 @@
+;;; osc-tests.el --- Tests for osc.el  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Matthias Meulien <orontee@gmail.com>
+;; Keywords:
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'osc)
+(require 'ert)
+
+(defvar osc-tests--strings
+  `(
+    ("Hello World" "Hello World")
+
+    ;; window title
+    ("Buffer \e]2;A window title\e\\content" "Buffer content")
+
+    ;; window title
+    ("Unfinished \e]2;window title" "Unfinished \e]2;window title")
+
+    ;; current directory
+    ("\e]7;file://127.0.0.1/tmp\e\\user@host$ " "user@host$ ")
+
+    ;; hyperlink
+    ("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\" "This is a link")
+    ))
+;; Don't output those strings to stdout since they may have
+;; side-effects on the environment
+
+(ert-deftest osc-tests-apply-region-no-handlers ()
+  (let ((osc-handlers nil))
+    (pcase-dolist (`(,input ,text) osc-tests--strings)
+      (with-temp-buffer
+        (insert input)
+        (osc-apply-on-region (point-min) (point-max))
+        (should (equal (buffer-string) text))))))
-- 
2.30.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Handle-OSC-command-to-set-window-title.patch --]
[-- Type: text/x-diff, Size: 1837 bytes --]

From 524d7a10bf5b0db16410d00b11376bca73f69eba Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sat, 17 Sep 2022 17:54:24 +0200
Subject: [PATCH 2/3] Handle OSC command to set window title

* lisp/osc.el (osc-handlers):
(osc-window-title):
(osc-window-title-handler):
---
 lisp/osc.el | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/osc.el b/lisp/osc.el
index 224981a856..619972dab1 100644
--- a/lisp/osc.el
+++ b/lisp/osc.el
@@ -23,12 +23,13 @@
 ;;; Commentary:
 
 ;; Interpretation of OSC (Operating System Commands) escape
-;; sequences. Handlers for OSC 7 and 8 (for current directory and
-;; hyperlinks respectively) are provided.
+;; sequences. Handlers for OSC 2, 7 and 8 (for window title, current
+;; directory and hyperlinks respectively) are provided.
 
 ;;; Code:
 
-(defvar-local osc-handlers '(("7" . osc-directory-tracker)
+(defvar-local osc-handlers '(("2" . osc-window-title-handler)
+                             ("7" . osc-directory-tracker)
                              ("8" . osc-hyperlink-handler))
   "Alist of handlers for OSC escape sequences.
 See `osc-apply-on-region' for details.")
@@ -67,6 +68,18 @@ osc-apply-on-region
           (put-text-property pos0 end 'invisible t)
           (setq osc--marker (copy-marker pos0)))))))
 
+;; Window title handling (OSC 2)
+
+(defvar-local osc-window-title nil)
+(defun osc-window-title-handler (_ text)
+  "Set value of `osc-window-title' from an OSC 2 escape sequence.
+The variable `osc-window-title' can be referred to in
+`frame-title-format' to dynamically set the frame title.
+
+This function is intended to be included as an entry of
+`osc-handlers'."
+  (setq osc-window-title text))
+
 ;; Current directory tracking (OSC 7)
 
 (declare-function url-host "url/url-parse.el")
-- 
2.30.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-OSC-escape-sequences-filter-for-compilation-buffer.patch --]
[-- Type: text/x-diff, Size: 2946 bytes --]

From 1d179481023869b3216d7023713d547a3d45bcd8 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sat, 17 Sep 2022 18:59:31 +0200
Subject: [PATCH 3/3] OSC escape sequences filter for compilation buffer

* lisp/osc.el (osc-control-seq-regexp):
(osc-filter-region):
(osc-for-compilation-buffer):
(osc-compilation-filter):
---
 lisp/osc.el | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/lisp/osc.el b/lisp/osc.el
index 619972dab1..89467bc4cf 100644
--- a/lisp/osc.el
+++ b/lisp/osc.el
@@ -26,8 +26,26 @@
 ;; sequences. Handlers for OSC 2, 7 and 8 (for window title, current
 ;; directory and hyperlinks respectively) are provided.
 
+;; The function `osc-compilation-filter' can be added to
+;; `compilation-filter-hook' to collect OSC sequences in compilation
+;; buffers. The variable `osc-for-compilation-buffer' tells what to do
+;; with collected sequences.
+
 ;;; Code:
 
+(defconst osc-control-seq-regexp
+  ;; See ECMA 48, section 8.3.89 "OSC - OPERATING SYSTEM COMMAND".
+  "\e\\][\x08-\x0D]*[\x20-\x7E]*\\(\a\\|\e\\\\\\)"
+  "Regexp matching an OSC control sequence.")
+
+(defun osc-filter-region (begin end)
+  "Filter out all OSC control sequences from region BEGIN to END."
+  (save-excursion
+    (goto-char begin)
+    ;; Delete escape sequences.
+    (while (re-search-forward osc-control-seq-regexp end t)
+      (delete-region (match-beginning 0) (match-end 0)))))
+
 (defvar-local osc-handlers '(("2" . osc-window-title-handler)
                              ("7" . osc-directory-tracker)
                              ("8" . osc-hyperlink-handler))
@@ -136,5 +154,35 @@ osc-hyperlink-handler
         (and (string-match ";\\(.+\\)" text)
              (cons (point-marker) (match-string-no-properties 1 text)))))
 
+(defcustom osc-for-compilation-buffer 'filter
+  "Determines what to do of OSC escape sequences in compilation output.
+If nil, do nothing.
+
+If the symbol `filter', then filter out all OSC control sequences.
+
+If anything else (such as t), then collect OSC control sequences
+and call appropriate handler as described in `osc-handlers'.
+
+In order for this to have any effect, `osc-compilation-filter'
+must be in `compilation-filter-hook'."
+  :type '(choice (const :tag "Do nothing" nil)
+                 (const :tag "Filter" filter)
+                 (other :tag "Translate" t))
+  :group 'osc
+  :version "29.0")
+
+;;;###autoload
+(defun osc-compilation-filter ()
+  "Maybe collect OSC control sequences.
+This function depends on the `osc-for-compilation-buffer'
+variable, and is meant to be used in `compilation-filter-hook'."
+  (let ((inhibit-read-only t))
+    (pcase osc-for-compilation-buffer
+      ('nil nil)
+      ('filter
+       (osc-filter-region compilation-filter-start (point)))
+      (_
+       (osc-apply-on-region compilation-filter-start (point))))))
+
 (provide 'osc)
 ;;; osc.el ends here
-- 
2.30.2


[-- Attachment #5: Type: text/plain, Size: 68 bytes --]


The second patch obsolete the one provided in bug#57866.

Matthias

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-17 17:21     ` Matthias Meulien
@ 2022-09-18 10:33       ` Lars Ingebrigtsen
  2022-09-18 12:45         ` Matthias Meulien
  0 siblings, 1 reply; 21+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-18 10:33 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821

Matthias Meulien <orontee@gmail.com> writes:

> Here are three patchs that:
> - Extract current support of OSC escape sequences from comint.el
> - Handle OSC command to set window title
> - Provide an OSC escape sequences filter for compilation buffer

Thanks; looks good to me except for the commit messages:

> * lisp/osc.el (osc-control-seq-regexp):
> (osc-filter-region):
> (osc-for-compilation-buffer):
> (osc-compilation-filter):

You're supposed to type in after the colon what the change for the
relevant item does.  :-)






^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 10:33       ` Lars Ingebrigtsen
@ 2022-09-18 12:45         ` Matthias Meulien
  2022-09-18 12:52           ` Lars Ingebrigtsen
  2022-09-18 15:19           ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 21+ messages in thread
From: Matthias Meulien @ 2022-09-18 12:45 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 57821

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> You're supposed to type in after the colon what the change for the
> relevant item does.  :-)

😁 Sure.  Here are updated patches.  I also fixed the aliases: One was
missing (comint-osc-handlers) and one name was wrong
(comint-osc-hyperlink).

Note that I've not written any News entry.  Should I? For each patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Extract-support-of-OSC-escape-sequences-from-comint.patch --]
[-- Type: text/x-diff, Size: 13601 bytes --]

From d31b6bf5ce7a3ad63aacf21d815f78eef5fa1404 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sun, 18 Sep 2022 13:54:46 +0200
Subject: [PATCH 1/3] Extract support of OSC escape sequences from comint

* lisp/comint.el (osc): Now requires osc.el.
(comint-osc-directory-tracker): Alias to osc-directory-tracker.
(comint-osc-hyperlink-handler): Alias to osc-hyperlink-handler.
(comint-osc-hyperlink-map): Alias to osc-hyperlink-map.
(comint-osc-handlers): Alias to osc-handlers.
(comint-osc-hyperlink): Alias to osc-hyperlink.
(comint-osc-process-output): Rewritten to call osc-apply-on-region.
* lisp/osc.el (osc-handlers): Clone comint-osc-handlers.
(osc--marker): Clone comint-osc--marker.
(osc-apply-on-region): Implementation taken from comint-osc-process-output.
(osc-directory-tracker): Clone from comint-osc-directory-tracker.
(osc-hyperlink-map): Clone from comint-osc-hyperlink-map.
(osc-hyperlink): Clone from comint-osc-hyperlink.
(osc-hyperlink--state): Clone from comint-osc-hyperlink--state.
(osc-hyperlink-handler): Clone from comint-osc-hyperlink-handler.
* test/lisp/osc-tests.el (osc): Test osc-apply-region.
---
 lisp/comint.el         |  92 ++++-------------------------
 lisp/osc.el            | 127 +++++++++++++++++++++++++++++++++++++++++
 test/lisp/osc-tests.el |  57 ++++++++++++++++++
 3 files changed, 195 insertions(+), 81 deletions(-)
 create mode 100644 lisp/osc.el
 create mode 100644 test/lisp/osc-tests.el

diff --git a/lisp/comint.el b/lisp/comint.el
index 696dac3d12..afaa27c2c0 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -103,6 +103,7 @@
 
 (require 'ring)
 (require 'ansi-color)
+(require 'osc)
 (require 'regexp-opt)                   ;For regexp-opt-charset.
 (eval-when-compile (require 'subr-x))
 \f
@@ -3914,12 +3915,12 @@ comint-redirect-results-list-from-process
 ;; to `comint-osc-handlers' allows a customized treatment of further
 ;; sequences.
 
-(defvar-local comint-osc-handlers '(("7" . comint-osc-directory-tracker)
-                                    ("8" . comint-osc-hyperlink-handler))
-  "Alist of handlers for OSC escape sequences.
-See `comint-osc-process-output' for details.")
-
-(defvar-local comint-osc--marker nil)
+;; Aliases defined for reverse compatibility
+(defalias 'comint-osc-handlers 'osc-handlers)
+(defalias 'comint-osc-directory-tracker 'osc-directory-tracker)
+(defalias 'comint-osc-hyperlink-handler 'osc-hyperlink-handler)
+(defalias 'comint-osc-hyperlink 'osc-hyperlink)
+(defalias 'comint-osc-hyperlink-map 'osc-hyperlink-map)
 
 (defun comint-osc-process-output (_)
   "Interpret OSC escape sequences in comint output.
@@ -3935,81 +3936,10 @@ comint-osc-process-output
 `comint-osc-handlers' alist, the corresponding value, which
 should be a function, is called with `command' and `text' as
 arguments, with point where the escape sequence was located."
-  (let ((bound (process-mark (get-buffer-process (current-buffer)))))
-    (save-excursion
-      ;; Start one char before last output to catch a possibly stray ESC
-      (goto-char (or comint-osc--marker (1- comint-last-output-start)))
-      (when (eq (char-before) ?\e) (backward-char))
-      (while (re-search-forward "\e]" bound t)
-        (let ((pos0 (match-beginning 0))
-              (code (and (re-search-forward "\\=\\([0-9A-Za-z]*\\);" bound t)
-                         (match-string 1)))
-              (pos1 (point)))
-          (if (re-search-forward "\a\\|\e\\\\" bound t)
-              (let ((text (buffer-substring-no-properties
-                           pos1 (match-beginning 0))))
-                (setq comint-osc--marker nil)
-                (delete-region pos0 (point))
-                (when-let ((fun (cdr (assoc-string code comint-osc-handlers))))
-                  (funcall fun code text)))
-            (put-text-property pos0 bound 'invisible t)
-            (setq comint-osc--marker (copy-marker pos0))))))))
-
-;; Current directory tracking (OSC 7)
-
-(declare-function url-host "url/url-parse.el")
-(declare-function url-type "url/url-parse.el")
-(declare-function url-filename "url/url-parse.el")
-(defun comint-osc-directory-tracker (_ text)
-  "Update `default-directory' from OSC 7 escape sequences.
-
-This function is intended to be included as an entry of
-`comint-osc-handlers'.  You should moreover arrange for your
-shell to print the appropriate escape sequence at each prompt,
-say with the following command:
-
-    printf \"\\e]7;file://%s%s\\e\\\\\" \"$HOSTNAME\" \"$PWD\"
-
-This functionality serves as an alternative to `dirtrack-mode'
-and `shell-dirtrack-mode'."
-  (let ((url (url-generic-parse-url text)))
-    (when (and (string= (url-type url) "file")
-               (or (null (url-host url))
-                   (string= (url-host url) (system-name))))
-      (ignore-errors
-        (cd-absolute (url-unhex-string (url-filename url)))))))
-
-;; Hyperlink handling (OSC 8)
-
-(defvar comint-osc-hyperlink-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-c\r" 'browse-url-button-open)
-    (define-key map [mouse-2] 'browse-url-button-open)
-    (define-key map [follow-link] 'mouse-face)
-    map)
-  "Keymap used by OSC 8 hyperlink buttons.")
-
-(define-button-type 'comint-osc-hyperlink
-  'keymap comint-osc-hyperlink-map
-  'help-echo (lambda (_ buffer pos)
-               (when-let ((url (get-text-property pos 'browse-url-data buffer)))
-                 (format "mouse-2, C-c RET: Open %s" url))))
-
-(defvar-local comint-osc-hyperlink--state nil)
-
-(defun comint-osc-hyperlink-handler (_ text)
-  "Create a hyperlink from an OSC 8 escape sequence.
-This function is intended to be included as an entry of
-`comint-osc-handlers'."
-  (when comint-osc-hyperlink--state
-    (let ((start (car comint-osc-hyperlink--state))
-          (url (cdr comint-osc-hyperlink--state)))
-      (make-text-button start (point)
-                        'type 'comint-osc-hyperlink
-                        'browse-url-data url)))
-  (setq comint-osc-hyperlink--state
-        (and (string-match ";\\(.+\\)" text)
-             (cons (point-marker) (match-string-no-properties 1 text)))))
+  (let ((start (1- comint-last-output-start))
+        ;; Start one char before last output to catch a possibly stray ESC
+        (bound (process-mark (get-buffer-process (current-buffer)))))
+    (osc-apply-on-region start bound)))
 
 \f
 ;;; Input fontification and indentation through an indirect buffer
diff --git a/lisp/osc.el b/lisp/osc.el
new file mode 100644
index 0000000000..224981a856
--- /dev/null
+++ b/lisp/osc.el
@@ -0,0 +1,127 @@
+;;; osc.el --- Support for OSC escape sequences      -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022  Free Software Foundation, Inc.
+
+;; Author: Augusto Stoffel <arstoffel@gmail.com>
+;;         Matthias Meulien <orontee@gmail.com>
+;; Maintainer: emacs-devel@gnu.org
+;; Keywords: processes, terminals, services
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Interpretation of OSC (Operating System Commands) escape
+;; sequences. Handlers for OSC 7 and 8 (for current directory and
+;; hyperlinks respectively) are provided.
+
+;;; Code:
+
+(defvar-local osc-handlers '(("7" . osc-directory-tracker)
+                             ("8" . osc-hyperlink-handler))
+  "Alist of handlers for OSC escape sequences.
+See `osc-apply-on-region' for details.")
+
+(defvar-local osc--marker nil)
+;; The function `osc-apply-on-region' can set `osc--marker' to the start
+;; position of an escape sequence without termination.
+
+(defun osc-apply-on-region (begin end)
+  "Interpret OSC escape sequences in region.
+This function search for escape sequences of the forms
+
+    ESC ] command ; text BEL
+    ESC ] command ; text ESC \\
+
+Every occurrence of such escape sequences is removed from the
+buffer.  Then, if `command' is a key of the local variable
+`osc-handlers' alist, the corresponding value, which should be a
+function, is called with `command' and `text' as arguments, with
+point where the escape sequence was located."
+  (save-excursion
+    (goto-char (or osc--marker begin))
+    (when (eq (char-before) ?\e) (backward-char))
+    (while (re-search-forward "\e]" end t)
+      (let ((pos0 (match-beginning 0))
+            (code (and (re-search-forward "\\=\\([0-9A-Za-z]*\\);" end t)
+                       (match-string 1)))
+            (pos1 (point)))
+        (if (re-search-forward "\a\\|\e\\\\" end t)
+            (let ((text (buffer-substring-no-properties
+                         pos1 (match-beginning 0))))
+              (setq osc--marker nil)
+              (delete-region pos0 (point))
+              (when-let ((fun (cdr (assoc-string code osc-handlers))))
+                (funcall fun code text)))
+          (put-text-property pos0 end 'invisible t)
+          (setq osc--marker (copy-marker pos0)))))))
+
+;; Current directory tracking (OSC 7)
+
+(declare-function url-host "url/url-parse.el")
+(declare-function url-type "url/url-parse.el")
+(declare-function url-filename "url/url-parse.el")
+(defun osc-directory-tracker (_ text)
+  "Update `default-directory' from OSC 7 escape sequences.
+
+This function is intended to be included as an entry of
+`osc-handlers'.  You should moreover arrange for your shell to
+print the appropriate escape sequence at each prompt, say with
+the following command:
+
+    printf \"\\e]7;file://%s%s\\e\\\\\" \"$HOSTNAME\" \"$PWD\"
+
+This functionality serves as an alternative to `dirtrack-mode'
+and `shell-dirtrack-mode'."
+  (let ((url (url-generic-parse-url text)))
+    (when (and (string= (url-type url) "file")
+               (or (null (url-host url))
+                   (string= (url-host url) (system-name))))
+      (ignore-errors
+        (cd-absolute (url-unhex-string (url-filename url)))))))
+
+;; Hyperlink handling (OSC 8)
+
+(defvar osc-hyperlink-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\r" 'browse-url-button-open)
+    (define-key map [mouse-2] 'browse-url-button-open)
+    (define-key map [follow-link] 'mouse-face)
+    map)
+  "Keymap used by OSC 8 hyperlink buttons.")
+
+(define-button-type 'osc-hyperlink
+  'keymap osc-hyperlink-map
+  'help-echo (lambda (_ buffer pos)
+               (when-let ((url (get-text-property pos 'browse-url-data buffer)))
+                 (format "mouse-2, C-c RET: Open %s" url))))
+
+(defvar-local osc-hyperlink--state nil)
+
+(defun osc-hyperlink-handler (_ text)
+  "Create a hyperlink from an OSC 8 escape sequence.
+This function is intended to be included as an entry of
+`osc-handlers'."
+  (when osc-hyperlink--state
+    (let ((start (car osc-hyperlink--state))
+          (url (cdr osc-hyperlink--state)))
+      (make-text-button start (point)
+                        'type 'osc-hyperlink
+                        'browse-url-data url)))
+  (setq osc-hyperlink--state
+        (and (string-match ";\\(.+\\)" text)
+             (cons (point-marker) (match-string-no-properties 1 text)))))
+
+(provide 'osc)
+;;; osc.el ends here
diff --git a/test/lisp/osc-tests.el b/test/lisp/osc-tests.el
new file mode 100644
index 0000000000..d53bab08d3
--- /dev/null
+++ b/test/lisp/osc-tests.el
@@ -0,0 +1,57 @@
+;;; osc-tests.el --- Tests for osc.el  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Matthias Meulien <orontee@gmail.com>
+;; Keywords:
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'osc)
+(require 'ert)
+
+(defvar osc-tests--strings
+  `(
+    ("Hello World" "Hello World")
+
+    ;; window title
+    ("Buffer \e]2;A window title\e\\content" "Buffer content")
+
+    ;; window title
+    ("Unfinished \e]2;window title" "Unfinished \e]2;window title")
+
+    ;; current directory
+    ("\e]7;file://127.0.0.1/tmp\e\\user@host$ " "user@host$ ")
+
+    ;; hyperlink
+    ("\e]8;;http://example.com\e\\This is a link\e]8;;\e\\" "This is a link")
+    ))
+;; Don't output those strings to stdout since they may have
+;; side-effects on the environment
+
+(ert-deftest osc-tests-apply-region-no-handlers ()
+  (let ((osc-handlers nil))
+    (pcase-dolist (`(,input ,text) osc-tests--strings)
+      (with-temp-buffer
+        (insert input)
+        (osc-apply-on-region (point-min) (point-max))
+        (should (equal (buffer-string) text))))))
-- 
2.30.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Handle-OSC-command-to-set-window-title.patch --]
[-- Type: text/x-diff, Size: 1995 bytes --]

From 5b80b2444b5c27315e39303637ec4356218c400b Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sat, 17 Sep 2022 17:54:24 +0200
Subject: [PATCH 2/3] Handle OSC command to set window title

* lisp/osc.el (osc-handlers): Bind osc-window-title-handler to OSC
command 2.
(osc-window-title): Local variable storing string extracted from OSC
command 2.
(osc-window-title-handler): Copy text from OSC command 2 to
osc-window-title.
---
 lisp/osc.el | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/osc.el b/lisp/osc.el
index 224981a856..619972dab1 100644
--- a/lisp/osc.el
+++ b/lisp/osc.el
@@ -23,12 +23,13 @@
 ;;; Commentary:
 
 ;; Interpretation of OSC (Operating System Commands) escape
-;; sequences. Handlers for OSC 7 and 8 (for current directory and
-;; hyperlinks respectively) are provided.
+;; sequences. Handlers for OSC 2, 7 and 8 (for window title, current
+;; directory and hyperlinks respectively) are provided.
 
 ;;; Code:
 
-(defvar-local osc-handlers '(("7" . osc-directory-tracker)
+(defvar-local osc-handlers '(("2" . osc-window-title-handler)
+                             ("7" . osc-directory-tracker)
                              ("8" . osc-hyperlink-handler))
   "Alist of handlers for OSC escape sequences.
 See `osc-apply-on-region' for details.")
@@ -67,6 +68,18 @@ osc-apply-on-region
           (put-text-property pos0 end 'invisible t)
           (setq osc--marker (copy-marker pos0)))))))
 
+;; Window title handling (OSC 2)
+
+(defvar-local osc-window-title nil)
+(defun osc-window-title-handler (_ text)
+  "Set value of `osc-window-title' from an OSC 2 escape sequence.
+The variable `osc-window-title' can be referred to in
+`frame-title-format' to dynamically set the frame title.
+
+This function is intended to be included as an entry of
+`osc-handlers'."
+  (setq osc-window-title text))
+
 ;; Current directory tracking (OSC 7)
 
 (declare-function url-host "url/url-parse.el")
-- 
2.30.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-OSC-escape-sequences-filter-for-compilation-buffer.patch --]
[-- Type: text/x-diff, Size: 3164 bytes --]

From fc0dd679efc62b72588ab2d7cd0efcd67221e5cf Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sat, 17 Sep 2022 18:59:31 +0200
Subject: [PATCH 3/3] OSC escape sequences filter for compilation buffer

* lisp/osc.el (osc-control-seq-regexp): Regexp matching OSC control sequence.
(osc-filter-region): Filter out OSC control sequences from region.
(osc-for-compilation-buffer): Determines what to do with OSC escape
sequences in compilation output.
(osc-compilation-filter): Implement OSC escape sequence handling for
compilation output.
---
 lisp/osc.el | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/lisp/osc.el b/lisp/osc.el
index 619972dab1..89467bc4cf 100644
--- a/lisp/osc.el
+++ b/lisp/osc.el
@@ -26,8 +26,26 @@
 ;; sequences. Handlers for OSC 2, 7 and 8 (for window title, current
 ;; directory and hyperlinks respectively) are provided.
 
+;; The function `osc-compilation-filter' can be added to
+;; `compilation-filter-hook' to collect OSC sequences in compilation
+;; buffers. The variable `osc-for-compilation-buffer' tells what to do
+;; with collected sequences.
+
 ;;; Code:
 
+(defconst osc-control-seq-regexp
+  ;; See ECMA 48, section 8.3.89 "OSC - OPERATING SYSTEM COMMAND".
+  "\e\\][\x08-\x0D]*[\x20-\x7E]*\\(\a\\|\e\\\\\\)"
+  "Regexp matching an OSC control sequence.")
+
+(defun osc-filter-region (begin end)
+  "Filter out all OSC control sequences from region BEGIN to END."
+  (save-excursion
+    (goto-char begin)
+    ;; Delete escape sequences.
+    (while (re-search-forward osc-control-seq-regexp end t)
+      (delete-region (match-beginning 0) (match-end 0)))))
+
 (defvar-local osc-handlers '(("2" . osc-window-title-handler)
                              ("7" . osc-directory-tracker)
                              ("8" . osc-hyperlink-handler))
@@ -136,5 +154,35 @@ osc-hyperlink-handler
         (and (string-match ";\\(.+\\)" text)
              (cons (point-marker) (match-string-no-properties 1 text)))))
 
+(defcustom osc-for-compilation-buffer 'filter
+  "Determines what to do of OSC escape sequences in compilation output.
+If nil, do nothing.
+
+If the symbol `filter', then filter out all OSC control sequences.
+
+If anything else (such as t), then collect OSC control sequences
+and call appropriate handler as described in `osc-handlers'.
+
+In order for this to have any effect, `osc-compilation-filter'
+must be in `compilation-filter-hook'."
+  :type '(choice (const :tag "Do nothing" nil)
+                 (const :tag "Filter" filter)
+                 (other :tag "Translate" t))
+  :group 'osc
+  :version "29.0")
+
+;;;###autoload
+(defun osc-compilation-filter ()
+  "Maybe collect OSC control sequences.
+This function depends on the `osc-for-compilation-buffer'
+variable, and is meant to be used in `compilation-filter-hook'."
+  (let ((inhibit-read-only t))
+    (pcase osc-for-compilation-buffer
+      ('nil nil)
+      ('filter
+       (osc-filter-region compilation-filter-start (point)))
+      (_
+       (osc-apply-on-region compilation-filter-start (point))))))
+
 (provide 'osc)
 ;;; osc.el ends here
-- 
2.30.2


[-- Attachment #5: Type: text/plain, Size: 17 bytes --]





-- 
Matthias

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 12:45         ` Matthias Meulien
@ 2022-09-18 12:52           ` Lars Ingebrigtsen
  2022-09-18 13:42             ` Matthias Meulien
  2022-09-18 15:19           ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 21+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-18 12:52 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821

Matthias Meulien <orontee@gmail.com> writes:

> 😁 Sure.  Here are updated patches.  I also fixed the aliases: One was
> missing (comint-osc-handlers) and one name was wrong
> (comint-osc-hyperlink).

Thanks; pushed to Emacs 29.

> Note that I've not written any News entry.  Should I? For each patch?

I think one NEWS entry would be enough...





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 12:52           ` Lars Ingebrigtsen
@ 2022-09-18 13:42             ` Matthias Meulien
  2022-09-18 13:46               ` Lars Ingebrigtsen
                                 ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Matthias Meulien @ 2022-09-18 13:42 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 57821

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Matthias Meulien <orontee@gmail.com> writes:
>
>> 😁 Sure.  Here are updated patches.  I also fixed the aliases: One was
>> missing (comint-osc-handlers) and one name was wrong
>> (comint-osc-hyperlink).
>
> Thanks; pushed to Emacs 29.

Sorry for the warning... I forgot to check `make' output...

>> Note that I've not written any News entry.  Should I? For each patch?
>
> I think one NEWS entry would be enough...

Here it is:

diff --git a/etc/NEWS b/etc/NEWS
index ae3f84c1b9..a8101da229 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2440,6 +2440,18 @@ The old name is still available as an obsolete function alias.
 \f
 * New Modes and Packages in Emacs 29.1
 
+*** New package 'osc'.
+Support for OSC ("Operating System Command") espace sequences has been
+extracted from 'comint.el' in order to provide interpretation of OSC
+escape sequences in compilation buffers.
+
+Adding the new function 'osc-compilation-filter' to
+'compilation-filter-hook' enables interpretation of OSC ("Operating
+System Command") escape sequences in compilation buffers. By default,
+all sequences are filtered out.
+
+A handler for OSC 2, the command to set a window title, is provided.
+
 +++
 ** New commands 'image-crop' and 'image-elide'.
 These commands allow interactively cropping/eliding the image at
 
-- 
Matthias





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 13:42             ` Matthias Meulien
@ 2022-09-18 13:46               ` Lars Ingebrigtsen
  2022-09-18 15:19               ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-09-18 19:03               ` Jose A Ortega Ruiz
  2 siblings, 0 replies; 21+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-18 13:46 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821

Matthias Meulien <orontee@gmail.com> writes:

>> I think one NEWS entry would be enough...
>
> Here it is:

Thanks; pushed to Emacs 29.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 12:45         ` Matthias Meulien
  2022-09-18 12:52           ` Lars Ingebrigtsen
@ 2022-09-18 15:19           ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 21+ messages in thread
From: Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-09-18 15:19 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821, Lars Ingebrigtsen

Matthias Meulien [2022-09-18 14:45 +0200] wrote:

> I also fixed the aliases: One was missing (comint-osc-handlers) and
> one name was wrong (comint-osc-hyperlink).

[...]

> +;; Aliases defined for reverse compatibility
> +(defalias 'comint-osc-handlers 'osc-handlers)
> +(defalias 'comint-osc-hyperlink-map 'osc-hyperlink-map)

These are variables, so should use defvaralias instead.

> +(defalias 'comint-osc-hyperlink 'osc-hyperlink)

This is a button type, so I guess the closest thing is making one the
:supertype of the other?

Thanks,

-- 
Basil





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 13:42             ` Matthias Meulien
  2022-09-18 13:46               ` Lars Ingebrigtsen
@ 2022-09-18 15:19               ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-09-18 15:45                 ` Matthias Meulien
  2022-09-18 19:03               ` Jose A Ortega Ruiz
  2 siblings, 1 reply; 21+ messages in thread
From: Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-09-18 15:19 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821, Lars Ingebrigtsen

Matthias Meulien [2022-09-18 15:42 +0200] wrote:

> +*** New package 'osc'.
> +Support for OSC ("Operating System Command") espace sequences has been
> +extracted from 'comint.el' in order to provide interpretation of OSC
> +escape sequences in compilation buffers.
> +
> +Adding the new function 'osc-compilation-filter' to
> +'compilation-filter-hook' enables interpretation of OSC ("Operating
> +System Command") escape sequences in compilation buffers. By default,
                                                           ^^
Two spaces after a full stop, here and in the other patches.

> +all sequences are filtered out.
> +
> +A handler for OSC 2, the command to set a window title, is provided.

Also OSC 7 and 8, no?

BTW, the commentary in comint.el doesn't mention OSC 2.

Thanks,

-- 
Basil





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 15:19               ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-09-18 15:45                 ` Matthias Meulien
  2022-09-18 16:27                   ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-09-19  8:17                   ` Lars Ingebrigtsen
  0 siblings, 2 replies; 21+ messages in thread
From: Matthias Meulien @ 2022-09-18 15:45 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 57821, Lars Ingebrigtsen

"Basil L. Contovounesios" <contovob@tcd.ie> writes:

> Matthias Meulien [2022-09-18 15:42 +0200] wrote:
>
>> +*** New package 'osc'.
>> +Support for OSC ("Operating System Command") espace sequences has been
>> +extracted from 'comint.el' in order to provide interpretation of OSC
>> +escape sequences in compilation buffers.
>> +
>> +Adding the new function 'osc-compilation-filter' to
>> +'compilation-filter-hook' enables interpretation of OSC ("Operating
>> +System Command") escape sequences in compilation buffers. By default,
>                                                            ^^
> Two spaces after a full stop, here and in the other patches.

Thanks for your careful reading!  I failed to found places with this
problem in the other patches...

>> +all sequences are filtered out.
>> +
>> +A handler for OSC 2, the command to set a window title, is provided.
>
> Also OSC 7 and 8, no?

Sure, I thought it's a new handler was implicit in the NEWS file; Other
handlers were already mentionned in NEWS.28. But let's try to be more
precise.

>
> BTW, the commentary in comint.el doesn't mention OSC 2.

+1

Here is a patch improving the news entry and fixing the defalias for
variables you mentionned in your other message.  I didn't tried to solve
the alias for the button; I'll have to learn more about aliases first, I
thought that just "maintaining" the symbol would be ok.

diff --git a/etc/NEWS b/etc/NEWS
index 88d00d9474..5fe96b0e0c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2441,11 +2441,12 @@ extracted from 'comint.el' in order to provide interpretation of OSC
 escape sequences in compilation buffers.
 
 Adding the new function 'osc-compilation-filter' to
-'compilation-filter-hook' enables interpretation of OSC ("Operating
-System Command") escape sequences in compilation buffers. By default,
-all sequences are filtered out.
+'compilation-filter-hook' enables interpretation of OSC escape
+sequences in compilation buffers.  By default, all sequences are
+filtered out.
 
-A handler for OSC 2, the command to set a window title, is provided.
+The list of handlers (covering OSC 7 and 8) has been extended with a
+handler for OSC 2, the command to set a window title.
 
 +++
 *** New user option 'project-vc-include-untracked'.
diff --git a/lisp/comint.el b/lisp/comint.el
index afaa27c2c0..202cf6eab5 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -3910,17 +3910,17 @@ comint-redirect-results-list-from-process
 ;;============================================================================
 ;; Adding `comint-osc-process-output' to
 ;; `comint-output-filter-functions' enables the interpretation of OSC
-;; escape sequences.  By default, OSC 7 and 8 (for current directory
-;; and hyperlinks respectively) are acted upon.  Adding more entries
-;; to `comint-osc-handlers' allows a customized treatment of further
-;; sequences.
+;; escape sequences.  By default, OSC 2, 7 and 8 (for window title,
+;; current directory and hyperlinks respectively) are acted upon.
+;; Adding more entries to `comint-osc-handlers' allows a customized
+;; treatment of further sequences.
 
 ;; Aliases defined for reverse compatibility
-(defalias 'comint-osc-handlers 'osc-handlers)
+(defvaralias 'comint-osc-handlers 'osc-handlers)
 (defalias 'comint-osc-directory-tracker 'osc-directory-tracker)
 (defalias 'comint-osc-hyperlink-handler 'osc-hyperlink-handler)
 (defalias 'comint-osc-hyperlink 'osc-hyperlink)
-(defalias 'comint-osc-hyperlink-map 'osc-hyperlink-map)
+(defvaralias 'comint-osc-hyperlink-map 'osc-hyperlink-map)
 
 (defun comint-osc-process-output (_)
   "Interpret OSC escape sequences in comint output.





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 15:45                 ` Matthias Meulien
@ 2022-09-18 16:27                   ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-09-19  8:17                   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 21+ messages in thread
From: Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-09-18 16:27 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: 57821, Lars Ingebrigtsen

Matthias Meulien [2022-09-18 17:45 +0200] wrote:

> "Basil L. Contovounesios" <contovob@tcd.ie> writes:
>
>> Two spaces after a full stop, here and in the other patches.
>
> Thanks for your careful reading!  I failed to found places with this
> problem in the other patches...

In the Commentary section of osc.el:

  ;; Interpretation of OSC (Operating System Commands) escape
  ;; sequences. Handlers for OSC 2, 7 and 8 (for window title, current
              ^^
  ;; directory and hyperlinks respectively) are provided.

  ;; The function `osc-compilation-filter' can be added to
  ;; `compilation-filter-hook' to collect OSC sequences in compilation
  ;; buffers. The variable `osc-for-compilation-buffer' tells what to do
            ^^
  ;; with collected sequences.

>>> +all sequences are filtered out.
>>> +
>>> +A handler for OSC 2, the command to set a window title, is provided.
>>
>> Also OSC 7 and 8, no?
>
> Sure, I thought it's a new handler was implicit in the NEWS file;

Saying "new package 'osc'" followed by "a handler for OSC 2 is provided"
sounds like that is the only handler provided by the new 'osc' package,
or at least like the entry is talking about what is true rather than
what is new.

> handlers were already mentionned in NEWS.28. But let's try to be more
> precise.

The new text LGTM.

> Here is a patch improving the news entry and fixing the defalias for
> variables you mentionned in your other message.  I didn't tried to solve
> the alias for the button; I'll have to learn more about aliases first, I
> thought that just "maintaining" the symbol would be ok.

Symbols have three distinct slots in which values can be stored: the
value slot, the function slot, and the property list slot.

defalias changes the function slot, so it's only appropriate for symbols
which are meant to be called as functions.

defvaralias changes the value slot, so it's only appropriate for symbols
which are meant to be used as variables.

Button types are just symbols that record certain information in their
property list, like which function to call when clicked, which face to
be fontified with, etc.

So in this case it's the button type's plist that needs to be
aliased/cloned.  AFAIK there is no built-in incantation for this, so I
guess you need to resort to either:
(a) manually calling symbol-plist + setplist;
(b) defining one button type as the supertype of the other; or
(c) not bothering with the compatibility alias at all.

Thanks,

-- 
Basil





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 13:42             ` Matthias Meulien
  2022-09-18 13:46               ` Lars Ingebrigtsen
  2022-09-18 15:19               ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-09-18 19:03               ` Jose A Ortega Ruiz
  2022-09-18 19:11                 ` Eli Zaretskii
  2 siblings, 1 reply; 21+ messages in thread
From: Jose A Ortega Ruiz @ 2022-09-18 19:03 UTC (permalink / raw)
  To: Matthias Meulien, Lars Ingebrigtsen; +Cc: 57821

On Sun, Sep 18 2022, Matthias Meulien wrote:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Matthias Meulien <orontee@gmail.com> writes:
>>
>>> 😁 Sure.  Here are updated patches.  I also fixed the aliases: One was
>>> missing (comint-osc-handlers) and one name was wrong
>>> (comint-osc-hyperlink).
>>
>> Thanks; pushed to Emacs 29.
>
> Sorry for the warning... I forgot to check `make' output...
>
>>> Note that I've not written any News entry.  Should I? For each patch?
>>
>> I think one NEWS entry would be enough...
>
> Here it is:
>
> diff --git a/etc/NEWS b/etc/NEWS
> index ae3f84c1b9..a8101da229 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -2440,6 +2440,18 @@ The old name is still available as an obsolete function alias.
>  \f
>  * New Modes and Packages in Emacs 29.1
>  
> +*** New package 'osc'.
> +Support for OSC ("Operating System Command") espace sequences has been

espace? :)

cheers,
jao
-- 
"In the beginning the Universe was created. This has made a lot of people
very angry and been widely regarded as a bad move."
 - Douglas Adams





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 19:03               ` Jose A Ortega Ruiz
@ 2022-09-18 19:11                 ` Eli Zaretskii
  2022-09-18 20:56                   ` Matthias Meulien
  0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2022-09-18 19:11 UTC (permalink / raw)
  To: Jose A Ortega Ruiz; +Cc: 57821, larsi, orontee

> Cc: 57821@debbugs.gnu.org
> From: Jose A Ortega Ruiz <jao@gnu.org>
> Date: Sun, 18 Sep 2022 20:03:56 +0100
> 
> > +*** New package 'osc'.
> > +Support for OSC ("Operating System Command") espace sequences has been
> 
> espace? :)

It should be epacse.





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 19:11                 ` Eli Zaretskii
@ 2022-09-18 20:56                   ` Matthias Meulien
  0 siblings, 0 replies; 21+ messages in thread
From: Matthias Meulien @ 2022-09-18 20:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 57821, larsi, Jose A Ortega Ruiz

Eli Zaretskii <eliz@gnu.org> writes:

>> Cc: 57821@debbugs.gnu.org
>> From: Jose A Ortega Ruiz <jao@gnu.org>
>> Date: Sun, 18 Sep 2022 20:03:56 +0100
>> 
>> > +*** New package 'osc'.
>> > +Support for OSC ("Operating System Command") espace sequences has been
>> 
>> espace? :)
>
> It should be epacse.

Thank you for your careful reading.
-- 
Matthias





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-18 15:45                 ` Matthias Meulien
  2022-09-18 16:27                   ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-09-19  8:17                   ` Lars Ingebrigtsen
  2022-09-19  8:38                     ` Matthias Meulien
  2022-09-19 18:12                     ` Matthias Meulien
  1 sibling, 2 replies; 21+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-19  8:17 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: Basil L. Contovounesios, 57821

Matthias Meulien <orontee@gmail.com> writes:

> Here is a patch improving the news entry and fixing the defalias for
> variables you mentionned in your other message.

I see that Eli has rewritten parts of the documentation here...  Can you
have a read of the current trunk and see whether there's anything more
to do here?





^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-19  8:17                   ` Lars Ingebrigtsen
@ 2022-09-19  8:38                     ` Matthias Meulien
  2022-09-19 18:12                     ` Matthias Meulien
  1 sibling, 0 replies; 21+ messages in thread
From: Matthias Meulien @ 2022-09-19  8:38 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Basil L. Contovounesios, 57821

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]

Sure, I'll do that before end of day.

Matthias

Le lun. 19 sept. 2022, 10:17, Lars Ingebrigtsen <larsi@gnus.org> a écrit :

> Matthias Meulien <orontee@gmail.com> writes:
>
> > Here is a patch improving the news entry and fixing the defalias for
> > variables you mentionned in your other message.
>
> I see that Eli has rewritten parts of the documentation here...  Can you
> have a read of the current trunk and see whether there's anything more
> to do here?
>

[-- Attachment #2: Type: text/html, Size: 890 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-19  8:17                   ` Lars Ingebrigtsen
  2022-09-19  8:38                     ` Matthias Meulien
@ 2022-09-19 18:12                     ` Matthias Meulien
  2022-09-19 18:47                       ` Lars Ingebrigtsen
  1 sibling, 1 reply; 21+ messages in thread
From: Matthias Meulien @ 2022-09-19 18:12 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Basil L. Contovounesios, 57821

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Matthias Meulien <orontee@gmail.com> writes:
>
>> Here is a patch improving the news entry and fixing the defalias for
>> variables you mentionned in your other message.
>
> I see that Eli has rewritten parts of the documentation here...  Can you
> have a read of the current trunk and see whether there's anything more
> to do here?

Here are the fixes left after Eli's work.  To my knowledge the only
known problem still to address is the renaming of the button type
comint-osc-hyperlink to osc-hyperlink; I've not found time to study
Basil advice.

diff --git a/etc/NEWS b/etc/NEWS
index 723bdd7c75..ee333a84e4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2450,7 +2450,9 @@ Adding the new function 'osc-compilation-filter' to
 sequences in compilation buffers.  By default, all sequences are
 filtered out.
 
-A handler for OSC 2, the command to set a window title, is provided.
+The list of handlers (already covering OSC 7 and 8) has been extended
+with a handler for OSC 2, the command to set a window title.
+
 
 +++
 *** New user option 'project-vc-include-untracked'.
diff --git a/lisp/comint.el b/lisp/comint.el
index afaa27c2c0..b2a04ea55a 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -3916,11 +3916,11 @@ comint-redirect-results-list-from-process
 ;; sequences.
 
 ;; Aliases defined for reverse compatibility
-(defalias 'comint-osc-handlers 'osc-handlers)
+(defvaralias 'comint-osc-handlers 'osc-handlers)
 (defalias 'comint-osc-directory-tracker 'osc-directory-tracker)
 (defalias 'comint-osc-hyperlink-handler 'osc-hyperlink-handler)
 (defalias 'comint-osc-hyperlink 'osc-hyperlink)
-(defalias 'comint-osc-hyperlink-map 'osc-hyperlink-map)
+(defvaralias 'comint-osc-hyperlink-map 'osc-hyperlink-map)
 
 (defun comint-osc-process-output (_)
   "Interpret OSC escape sequences in comint output.
diff --git a/lisp/osc.el b/lisp/osc.el
index 8f4cd630ba..14f7fe6a4f 100644
--- a/lisp/osc.el
+++ b/lisp/osc.el
@@ -22,14 +22,14 @@
 
 ;;; Commentary:
 
-;; Interpretation of OSC (Operating System Commands) escape
-;; sequences. Handlers for OSC 2, 7 and 8 (for window title, current
-;; directory and hyperlinks respectively) are provided.
+;; Interpretation of OSC (Operating System Commands) escape sequences.
+;; Handlers for OSC 2, 7 and 8 (for window title, current directory
+;; and hyperlinks respectively) are provided.
 
 ;; The function `osc-compilation-filter' can be added to
 ;; `compilation-filter-hook' to collect OSC sequences in compilation
-;; buffers. The variable `osc-for-compilation-buffer' tells what to do
-;; with collected sequences.
+;; buffers.  The variable `osc-for-compilation-buffer' tells what to
+;; do with collected sequences.
 
 ;;; Code:
 
-- 
Matthias





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer
  2022-09-19 18:12                     ` Matthias Meulien
@ 2022-09-19 18:47                       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 21+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-19 18:47 UTC (permalink / raw)
  To: Matthias Meulien; +Cc: Basil L. Contovounesios, 57821

Matthias Meulien <orontee@gmail.com> writes:

> Here are the fixes left after Eli's work.  To my knowledge the only
> known problem still to address is the renaming of the button type
> comint-osc-hyperlink to osc-hyperlink; I've not found time to study
> Basil advice.

Thanks; pushed to Emacs 29.





^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-09-19 18:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15  8:24 bug#57821: 29.0.50; ANSI sequence not filtered in compilation buffer Matthias Meulien
2022-09-15 11:13 ` Matthias Meulien
2022-09-16 11:20   ` Lars Ingebrigtsen
2022-09-16 20:59     ` Matthias Meulien
2022-09-17 17:21     ` Matthias Meulien
2022-09-18 10:33       ` Lars Ingebrigtsen
2022-09-18 12:45         ` Matthias Meulien
2022-09-18 12:52           ` Lars Ingebrigtsen
2022-09-18 13:42             ` Matthias Meulien
2022-09-18 13:46               ` Lars Ingebrigtsen
2022-09-18 15:19               ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-18 15:45                 ` Matthias Meulien
2022-09-18 16:27                   ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-19  8:17                   ` Lars Ingebrigtsen
2022-09-19  8:38                     ` Matthias Meulien
2022-09-19 18:12                     ` Matthias Meulien
2022-09-19 18:47                       ` Lars Ingebrigtsen
2022-09-18 19:03               ` Jose A Ortega Ruiz
2022-09-18 19:11                 ` Eli Zaretskii
2022-09-18 20:56                   ` Matthias Meulien
2022-09-18 15:19           ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).