From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matthias Meulien Newsgroups: gmane.emacs.bugs Subject: bug#58200: osc.el name conflict Date: Fri, 30 Sep 2022 23:19:01 +0200 Message-ID: <87wn9kwofu.fsf@gmail.com> References: <87h70o63p9.fsf@gmail.com> <871qrsk54g.fsf@gnus.org> <87czbc62u1.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="987"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 58200@debbugs.gnu.org, Augusto Stoffel , Stefan Monnier To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 30 23:20:41 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oeNR2-000Acc-Rj for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Sep 2022 23:20:41 +0200 Original-Received: from localhost ([::1]:34948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeNR1-0004sy-Ct for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Sep 2022 17:20:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeNQQ-0004sk-Iy for bug-gnu-emacs@gnu.org; Fri, 30 Sep 2022 17:20:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43984) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oeNQQ-00045A-9E for bug-gnu-emacs@gnu.org; Fri, 30 Sep 2022 17:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oeNQQ-0005CE-5A for bug-gnu-emacs@gnu.org; Fri, 30 Sep 2022 17:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matthias Meulien Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 30 Sep 2022 21:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58200 X-GNU-PR-Package: emacs Original-Received: via spool by 58200-submit@debbugs.gnu.org id=B58200.166457275519901 (code B ref 58200); Fri, 30 Sep 2022 21:20:02 +0000 Original-Received: (at 58200) by debbugs.gnu.org; 30 Sep 2022 21:19:15 +0000 Original-Received: from localhost ([127.0.0.1]:43062 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeNPe-0005At-5M for submit@debbugs.gnu.org; Fri, 30 Sep 2022 17:19:15 -0400 Original-Received: from mail-wm1-f51.google.com ([209.85.128.51]:44888) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeNPc-0005Ad-6u for 58200@debbugs.gnu.org; Fri, 30 Sep 2022 17:19:13 -0400 Original-Received: by mail-wm1-f51.google.com with SMTP id k3-20020a05600c1c8300b003b4fa1a85f8so2806691wms.3 for <58200@debbugs.gnu.org>; Fri, 30 Sep 2022 14:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date; bh=+PCrL51aylGxdAFm5eVPutyI8qsgXQgitaWDR/zMP6A=; b=IKZp24MLjuuY7bYyJl3Ug34yTa1cuVnMuE7EnwWQHUMKAvsyU3D+PonTfg4tTedfRf Mc113ayK5XYXkaDPbcyq+0JqVsigBwT14r5/tqiNVzYmF6TghGJ2aAYLVMylim/j8WgS Aq2KqqKh1qBSwMBuVakoZemNZsL57jikgB/5MzTFHZrCv2VgNbGI29nNZxitzyUovEkH GULCIk/7CHb6z3xJXeASZhX1n+ZU5OYrWBZ4GHPfrz0WRPn3uXtZ4OnWKfAVXge9yw8G jSLlYgvYhHfhkW3JCovDSDn87LVuWVUr/4gciNJhid36EOdOCVhFcBsh4MOLlmArF8nd ioHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=+PCrL51aylGxdAFm5eVPutyI8qsgXQgitaWDR/zMP6A=; b=qUstktEWji5yosTvMdBl0wKLUhTNmEEhoqpo/3F7mtgzEfrtScj3LDUgCIL13NFzgy c0/SVU+bbmVb68IKQz1LlObich5d+ZGklDFozwcJhCfavT1fyoFdCXshMekOBj5LSkPV MLCUMm7fNT9FhlJmHWpL4E/++l0X4DbHPnivVJq/QWdxQuq1K8GsfXaXhNXGlDH9NQ7A vtmPuzZsNsk/DZWfrB2nW6UwjYFhFqzT4TeJMhL6eESZ3WneBUfMVKmld1fL1z2gzn13 f26DqI2yjNRZ/Ty8K0dU98EAigy7UijiVJ69um4RvSLVprJg6qUcLjkO+tU11WaxtcIJ YqVQ== X-Gm-Message-State: ACrzQf3ba7XuiwsDr8muc2g1X/1Rr5iB7ItmLMOi8GEZNZn0GwSaknPC hyzCEMIamJ1vFDvTz3IN1nk= X-Google-Smtp-Source: AMsMyM6ObHkdJqvGiWO1SxXPphst/osxf5FjHcplDitubnuF/5c0E5lIvVDxgmJdVv+CnkqmERZB6g== X-Received: by 2002:a1c:cc0e:0:b0:3b4:fda3:c808 with SMTP id h14-20020a1ccc0e000000b003b4fda3c808mr79640wmb.146.1664572746114; Fri, 30 Sep 2022 14:19:06 -0700 (PDT) Original-Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb]) by smtp.gmail.com with ESMTPSA id e3-20020a5d5943000000b0022dd3aab6bfsm2153595wri.57.2022.09.30.14.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 14:19:03 -0700 (PDT) In-Reply-To: <87czbc62u1.fsf@gmail.com> (Matthias Meulien's message of "Fri, 30 Sep 2022 22:10:14 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:244064 Archived-At: --=-=-= Content-Type: text/plain Matthias Meulien writes: > Lars Ingebrigtsen writes: > >> Matthias Meulien writes: >> >>> Sure. And I can do the renaming, but what would be a good name? >>> What do you think of osc-sequences.el? >> >> Would ansi-osc.el be totally misleading? > > I am ok with that. > > My understanding was that OSC sequences are more related to ECMA because > the most precise description I read is here: > https://www.ecma-international.org/publications-and-standards/standards/ecma-48/ > but Wikipedia page on ANSI escape sequences tends to present OSC > sequences as a particular case of ANSI sequences, aligned with your > suggestion, > https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences. > > We could use the prefix ansi-osc- which isn't that long. A patch that renames related files and adds the ansi-osc- prefix is attached. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Rename-osc.el-to-ansi-osc.el-bug-58200.patch >From 1e027ba3498a040e32298dbddfd9ad1671bab46b Mon Sep 17 00:00:00 2001 From: Matthias Meulien Date: Fri, 30 Sep 2022 22:46:35 +0200 Subject: [PATCH] Rename osc.el to ansi-osc.el (bug#58200) * lisp/osc.el: Move from here... * lisp/ansi-osc.el: ...to here. * test/lisp/osc-tests.el: Move from here... * test/lisp/ansi-osc-tests.el: ...to here. --- etc/NEWS | 4 +- lisp/{osc.el => ansi-osc.el} | 105 +++++++++--------- lisp/comint.el | 14 +-- test/lisp/{osc-tests.el => ansi-osc-tests.el} | 12 +- 4 files changed, 68 insertions(+), 67 deletions(-) rename lisp/{osc.el => ansi-osc.el} (63%) rename test/lisp/{osc-tests.el => ansi-osc-tests.el} (85%) diff --git a/etc/NEWS b/etc/NEWS index b9c4ef62ce..ec23f10b1f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2577,12 +2577,12 @@ Enabling this minor mode turns on hiding header material, like 'elide-head' does; disabling it shows the header. The commands 'elide-head' and 'elide-head-show' are now obsolete. -*** New package osc.el. +*** New package ansi-osc.el. Support for OSC ("Operating System Command") escape sequences has been extracted from comint.el in order to provide interpretation of OSC sequences in compilation buffers. -Adding the new function 'osc-compilation-filter' to +Adding the new function 'ansi-osc-compilation-filter' to 'compilation-filter-hook' enables interpretation of OSC escape sequences in compilation buffers. By default, all sequences are filtered out. diff --git a/lisp/osc.el b/lisp/ansi-osc.el similarity index 63% rename from lisp/osc.el rename to lisp/ansi-osc.el index 14f7fe6a4f..67a8551628 100644 --- a/lisp/osc.el +++ b/lisp/ansi-osc.el @@ -1,4 +1,4 @@ -;;; osc.el --- Support for OSC escape sequences -*- lexical-binding: t; -*- +;;; ansi-osc.el --- Support for OSC escape sequences -*- lexical-binding: t; -*- ;; Copyright (C) 2022 Free Software Foundation, Inc. @@ -26,37 +26,37 @@ ;; 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 +;; The function `ansi-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 `ansi-osc-for-compilation-buffer' tells what +;; to do with collected sequences. ;;; Code: -(defconst osc-control-seq-regexp +(defconst ansi-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) +(defun ansi-osc-filter-region (begin end) "Filter out all OSC control sequences from region between BEGIN and END." (save-excursion (goto-char begin) ;; Delete escape sequences. - (while (re-search-forward osc-control-seq-regexp end t) + (while (re-search-forward ansi-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)) +(defvar-local ansi-osc-handlers '(("2" . ansi-osc-window-title-handler) + ("7" . ansi-osc-directory-tracker) + ("8" . ansi-osc-hyperlink-handler)) "Alist of handlers for OSC escape sequences. -See `osc-apply-on-region' for details.") +See `ansi-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. +(defvar-local ansi-osc--marker nil) +;; The function `ansi-osc-apply-on-region' can set `ansi-osc--marker' +;; to the start position of an escape sequence without termination. -(defun osc-apply-on-region (begin end) +(defun ansi-osc-apply-on-region (begin end) "Interpret OSC escape sequences in region between BEGIN and END. This function searches for escape sequences of the forms @@ -64,12 +64,13 @@ osc-apply-on-region ESC ] command ; text ESC \\ Every occurrence of such escape sequences is removed from the -buffer. Then, if `command' is a key in the alist that is the value -of the local variable `osc-handlers', that key's value, which should -be a function, is called with `command' and `text' as arguments, with -point where the escape sequence was located." +buffer. Then, if `command' is a key in the alist that is the +value of the local variable `ansi-osc-handlers', that key's +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)) + (goto-char (or ansi-osc--marker begin)) (when (eq (char-before) ?\e) (backward-char)) (while (re-search-forward "\e]" end t) (let ((pos0 (match-beginning 0)) @@ -79,35 +80,35 @@ osc-apply-on-region (if (re-search-forward "\a\\|\e\\\\" end t) (let ((text (buffer-substring-no-properties pos1 (match-beginning 0)))) - (setq osc--marker nil) + (setq ansi-osc--marker nil) (delete-region pos0 (point)) - (when-let ((fun (cdr (assoc-string code osc-handlers)))) + (when-let ((fun (cdr (assoc-string code ansi-osc-handlers)))) (funcall fun code text))) (put-text-property pos0 end 'invisible t) - (setq osc--marker (copy-marker pos0))))))) + (setq ansi-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 then be referenced in +(defvar-local ansi-osc-window-title nil) +(defun ansi-osc-window-title-handler (_ text) + "Set value of `ansi-osc-window-title' from an OSC 2 escape sequence. +The variable `ansi-osc-window-title' can then be referenced in `frame-title-format' to dynamically set the frame title. This function is intended to be included as an element of the -list that is the value of `osc-handlers'." - (setq osc-window-title text)) +list that is the value of `ansi-osc-handlers'." + (setq ansi-osc-window-title text)) ;; 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) +(defun ansi-osc-directory-tracker (_ text) "Update `default-directory' from OSC 7 escape sequences. This function is intended to be included as an element of the -the list that is the value of `osc-handlers'. You should arrange +the list that is the value of `ansi-osc-handlers'. You should arrange for your shell to print the appropriate escape sequence at each prompt, such as with the following command: @@ -124,7 +125,7 @@ osc-directory-tracker ;; Hyperlink handling (OSC 8) -(defvar osc-hyperlink-map +(defvar ansi-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) @@ -132,29 +133,29 @@ osc-hyperlink-map map) "Keymap used by OSC 8 hyperlink buttons.") -(define-button-type 'osc-hyperlink - 'keymap osc-hyperlink-map +(define-button-type 'ansi-osc-hyperlink + 'keymap ansi-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) +(defvar-local ansi-osc-hyperlink--state nil) -(defun osc-hyperlink-handler (_ text) +(defun ansi-osc-hyperlink-handler (_ text) "Create a hyperlink from an OSC 8 escape sequence. This function is intended to be included as an elemnt of the list -that is the value of `osc-handlers'." - (when osc-hyperlink--state - (let ((start (car osc-hyperlink--state)) - (url (cdr osc-hyperlink--state))) +that is the value of `ansi-osc-handlers'." + (when ansi-osc-hyperlink--state + (let ((start (car ansi-osc-hyperlink--state)) + (url (cdr ansi-osc-hyperlink--state))) (make-text-button start (point) - 'type 'osc-hyperlink + 'type 'ansi-osc-hyperlink 'browse-url-data url))) - (setq osc-hyperlink--state + (setq ansi-osc-hyperlink--state (and (string-match ";\\(.+\\)" text) (cons (point-marker) (match-string-no-properties 1 text))))) -(defcustom osc-for-compilation-buffer 'filter +(defcustom ansi-osc-for-compilation-buffer 'filter "What to do with OSC escape sequences in compilation output. If nil, do nothing. @@ -162,9 +163,9 @@ osc-for-compilation-buffer If the symbol `filter', then filter out all OSC control sequences. If any other non-nil value, then collect OSC control sequences -and call the appropriate handlers as described in `osc-handlers'. +and call the appropriate handlers as described in `ansi-osc-handlers'. -In order for this to have any effect, `osc-compilation-filter' +In order for this to have any effect, `ansi-osc-compilation-filter' must be in `compilation-filter-hook'." :type '(choice (const :tag "Do nothing" nil) (const :tag "Filter out OSC" filter) @@ -175,17 +176,17 @@ osc-for-compilation-buffer (defvar compilation-filter-start) ;;;###autoload -(defun osc-compilation-filter () +(defun ansi-osc-compilation-filter () "Maybe collect OSC control sequences. -This function depends on the variable `osc-for-compilation-buffer', +This function depends on the variable `ansi-osc-for-compilation-buffer', and is meant to be used in `compilation-filter-hook'." (let ((inhibit-read-only t)) - (pcase osc-for-compilation-buffer + (pcase ansi-osc-for-compilation-buffer ('nil nil) ('filter - (osc-filter-region compilation-filter-start (point))) + (ansi-osc-filter-region compilation-filter-start (point))) (_ - (osc-apply-on-region compilation-filter-start (point)))))) + (ansi-osc-apply-on-region compilation-filter-start (point)))))) -(provide 'osc) -;;; osc.el ends here +(provide 'ansi-osc) +;;; ansi-osc.el ends here diff --git a/lisp/comint.el b/lisp/comint.el index a70a75c648..b1f3ad8259 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -103,7 +103,7 @@ (require 'ring) (require 'ansi-color) -(require 'osc) +(require 'ansi-osc) (require 'regexp-opt) ;For regexp-opt-charset. (eval-when-compile (require 'subr-x)) @@ -3918,11 +3918,11 @@ comint-redirect-results-list-from-process ;; sequences. ;; Aliases defined for reverse compatibility -(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) -(defvaralias 'comint-osc-hyperlink-map 'osc-hyperlink-map) +(defvaralias 'comint-osc-handlers 'ansi-osc-handlers) +(defalias 'comint-osc-directory-tracker 'ansi-osc-directory-tracker) +(defalias 'comint-osc-hyperlink-handler 'ansi-osc-hyperlink-handler) +(defalias 'comint-osc-hyperlink 'ansi-osc-hyperlink) +(defvaralias 'comint-osc-hyperlink-map 'ansi-osc-hyperlink-map) (defun comint-osc-process-output (_) "Interpret OSC escape sequences in comint output. @@ -3941,7 +3941,7 @@ comint-osc-process-output (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))) + (ansi-osc-apply-on-region start bound))) ;;; Input fontification and indentation through an indirect buffer diff --git a/test/lisp/osc-tests.el b/test/lisp/ansi-osc-tests.el similarity index 85% rename from test/lisp/osc-tests.el rename to test/lisp/ansi-osc-tests.el index d53bab08d3..b3d66fb036 100644 --- a/test/lisp/osc-tests.el +++ b/test/lisp/ansi-osc-tests.el @@ -26,10 +26,10 @@ ;;; Code: -(require 'osc) +(require 'ansi-osc) (require 'ert) -(defvar osc-tests--strings +(defvar ansi-osc-tests--strings `( ("Hello World" "Hello World") @@ -48,10 +48,10 @@ osc-tests--strings ;; 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) +(ert-deftest ansi-osc-tests-apply-region-no-handlers () + (let ((ansi-osc-handlers nil)) + (pcase-dolist (`(,input ,text) ansi-osc-tests--strings) (with-temp-buffer (insert input) - (osc-apply-on-region (point-min) (point-max)) + (ansi-osc-apply-on-region (point-min) (point-max)) (should (equal (buffer-string) text)))))) -- 2.30.2 --=-=-= Content-Type: text/plain -- Matthias --=-=-=--