update packages
This commit is contained in:
@@ -1,32 +1,35 @@
|
||||
;;; with-editor.el --- Use the Emacsclient as $EDITOR -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2014-2020 The Magit Project Contributors
|
||||
;; Copyright (C) 2014-2022 The Magit Project Contributors
|
||||
;;
|
||||
;; You should have received a copy of the AUTHORS.md file. If not,
|
||||
;; see https://github.com/magit/with-editor/blob/master/AUTHORS.md.
|
||||
|
||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
||||
|
||||
;; Package-Requires: ((emacs "24.4") (async "1.9"))
|
||||
;; Keywords: tools
|
||||
;; Homepage: https://github.com/magit/with-editor
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
;; Package-Requires: ((emacs "24.4"))
|
||||
;; Package-Version: 3.0.5
|
||||
|
||||
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
;; This file 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, or (at your option)
|
||||
;; any later version.
|
||||
|
||||
;;
|
||||
;; This file 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 Magit. If not, see http://www.gnu.org/licenses.
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This library makes it possible to reliably use the Emacsclient as
|
||||
@@ -87,22 +90,13 @@
|
||||
(require 'server)
|
||||
(require 'shell)
|
||||
|
||||
(and (require 'async-bytecomp nil t)
|
||||
(let ((pkgs (bound-and-true-p async-bytecomp-allowed-packages)))
|
||||
(if (consp pkgs)
|
||||
(cl-intersection '(all magit) pkgs)
|
||||
(memq pkgs '(all t))))
|
||||
(fboundp 'async-bytecomp-package-mode)
|
||||
(async-bytecomp-package-mode 1))
|
||||
|
||||
(eval-when-compile
|
||||
(progn (require 'dired nil t)
|
||||
(require 'eshell nil t)
|
||||
(require 'term nil t)
|
||||
(condition-case err
|
||||
(require 'vterm nil t)
|
||||
(error (message "Error: %S" err)))
|
||||
(require 'vterm nil t)
|
||||
(error (message "Error(vterm): %S" err)))
|
||||
(require 'warnings nil t)))
|
||||
(declare-function dired-get-filename 'dired)
|
||||
(declare-function term-emulate-terminal 'term)
|
||||
@@ -327,12 +321,9 @@ And some tools that do not handle $EDITOR properly also break."
|
||||
(put 'with-editor-post-finish-hook 'permanent-local t)
|
||||
(put 'with-editor-post-cancel-hook 'permanent-local t)
|
||||
|
||||
(defvar with-editor-show-usage t)
|
||||
(defvar with-editor-cancel-message nil)
|
||||
(defvar with-editor-previous-winconf nil)
|
||||
(make-variable-buffer-local 'with-editor-show-usage)
|
||||
(make-variable-buffer-local 'with-editor-cancel-message)
|
||||
(make-variable-buffer-local 'with-editor-previous-winconf)
|
||||
(defvar-local with-editor-show-usage t)
|
||||
(defvar-local with-editor-cancel-message nil)
|
||||
(defvar-local with-editor-previous-winconf nil)
|
||||
(put 'with-editor-cancel-message 'permanent-local t)
|
||||
(put 'with-editor-previous-winconf 'permanent-local t)
|
||||
|
||||
@@ -637,9 +628,9 @@ Give PROCESS the new FILTER but keep `with-editor-process-filter'
|
||||
if that was added earlier by the advised `start-file-process'.
|
||||
|
||||
Do so by wrapping the two filter functions using a lambda, which
|
||||
becomes the actual filter. It calls `with-editor-process-filter'
|
||||
first, passing t as NO-STANDARD-FILTER. Then it calls FILTER,
|
||||
which may or may not insert the text into the PROCESS's buffer."
|
||||
becomes the actual filter. It calls FILTER first, which may or
|
||||
may not insert the text into the PROCESS's buffer. Then it calls
|
||||
`with-editor-process-filter', passing t as NO-STANDARD-FILTER."
|
||||
(set-process-filter
|
||||
process
|
||||
(if (eq (process-filter process) 'with-editor-process-filter)
|
||||
@@ -650,33 +641,49 @@ which may or may not insert the text into the PROCESS's buffer."
|
||||
|
||||
(defvar with-editor-filter-visit-hook nil)
|
||||
|
||||
(defun with-editor-output-filter (string)
|
||||
(defconst with-editor-sleeping-editor-regexp
|
||||
"^WITH-EDITOR: \\([0-9]+\\) OPEN \\([^]+?\\)\\(?: IN \\([^\r]+?\\)\\)?\r?$")
|
||||
|
||||
(defvar with-editor--max-incomplete-length 1000)
|
||||
|
||||
(defun with-editor-sleeping-editor-filter (process string)
|
||||
(when-let ((incomplete (and process (process-get process 'incomplete))))
|
||||
(setq string (concat incomplete string)))
|
||||
(save-match-data
|
||||
(if (string-match "^WITH-EDITOR: \
|
||||
\\([0-9]+\\) OPEN \\([^]+?\\)\
|
||||
\\(?: IN \\([^\r]+?\\)\\)?\r?$" string)
|
||||
(let ((pid (match-string 1 string))
|
||||
(file (match-string 2 string))
|
||||
(dir (match-string 3 string)))
|
||||
(unless (file-name-absolute-p file)
|
||||
(setq file (expand-file-name file dir)))
|
||||
(when default-directory
|
||||
(setq file (concat (file-remote-p default-directory) file)))
|
||||
(with-current-buffer (find-file-noselect file)
|
||||
(with-editor-mode 1)
|
||||
(setq with-editor--pid pid)
|
||||
(run-hooks 'with-editor-filter-visit-hook)
|
||||
(funcall (or (with-editor-server-window) 'switch-to-buffer)
|
||||
(current-buffer))
|
||||
(kill-local-variable 'server-window))
|
||||
nil)
|
||||
string)))
|
||||
(cond
|
||||
((and process (not (string-match-p "\n\\'" string)))
|
||||
(let ((length (length string)))
|
||||
(when (> length with-editor--max-incomplete-length)
|
||||
(setq string
|
||||
(substring string
|
||||
(- length with-editor--max-incomplete-length)))))
|
||||
(process-put process 'incomplete string)
|
||||
nil)
|
||||
((string-match with-editor-sleeping-editor-regexp string)
|
||||
(when process
|
||||
(process-put process 'incomplete nil))
|
||||
(let ((pid (match-string 1 string))
|
||||
(file (match-string 2 string))
|
||||
(dir (match-string 3 string)))
|
||||
(unless (file-name-absolute-p file)
|
||||
(setq file (expand-file-name file dir)))
|
||||
(when default-directory
|
||||
(setq file (concat (file-remote-p default-directory) file)))
|
||||
(with-current-buffer (find-file-noselect file)
|
||||
(with-editor-mode 1)
|
||||
(setq with-editor--pid pid)
|
||||
(run-hooks 'with-editor-filter-visit-hook)
|
||||
(funcall (or (with-editor-server-window) 'switch-to-buffer)
|
||||
(current-buffer))
|
||||
(kill-local-variable 'server-window)))
|
||||
nil)
|
||||
(t string))))
|
||||
|
||||
(defun with-editor-process-filter
|
||||
(process string &optional no-default-filter)
|
||||
"Listen for edit requests by child processes."
|
||||
(let ((default-directory (process-get process 'default-dir)))
|
||||
(with-editor-output-filter string))
|
||||
(with-editor-sleeping-editor-filter process string))
|
||||
(unless no-default-filter
|
||||
(internal-default-process-filter process string)))
|
||||
|
||||
@@ -706,7 +713,7 @@ This works in `shell-mode', `term-mode', `eshell-mode' and
|
||||
(interactive (list (with-editor-read-envvar)))
|
||||
(cond
|
||||
((derived-mode-p 'comint-mode 'term-mode)
|
||||
(let ((process (get-buffer-process (current-buffer))))
|
||||
(when-let ((process (get-buffer-process (current-buffer))))
|
||||
(goto-char (process-mark process))
|
||||
(process-send-string
|
||||
process (format " export %s=%s\n" envvar
|
||||
@@ -731,7 +738,9 @@ This works in `shell-mode', `term-mode', `eshell-mode' and
|
||||
(vterm-send-return))
|
||||
(when-let ((v (getenv "EMACS_SERVER_FILE")))
|
||||
(vterm-send-string (format "export EMACS_SERVER_FILE=%S" v))
|
||||
(vterm-send-return)))
|
||||
(vterm-send-return))
|
||||
(vterm-send-string "clear")
|
||||
(vterm-send-return))
|
||||
(error "Cannot use sleeping editor in this buffer")))
|
||||
(t
|
||||
(error "Cannot export environment variables in this buffer")))
|
||||
@@ -749,10 +758,16 @@ This works in `shell-mode', `term-mode', `eshell-mode' and
|
||||
(interactive)
|
||||
(with-editor-export-editor "HG_EDITOR"))
|
||||
|
||||
(defun with-editor-output-filter (string)
|
||||
"Handle edit requests on behalf of `comint-mode' and `eshell-mode'."
|
||||
(with-editor-sleeping-editor-filter nil string))
|
||||
|
||||
(defun with-editor-emulate-terminal (process string)
|
||||
"Like `term-emulate-terminal' but also handle edit requests."
|
||||
(when (with-editor-output-filter string)
|
||||
(term-emulate-terminal process string)))
|
||||
(let ((with-editor-sleeping-editor-regexp
|
||||
(substring with-editor-sleeping-editor-regexp 1)))
|
||||
(with-editor-sleeping-editor-filter process string))
|
||||
(term-emulate-terminal process string))
|
||||
|
||||
(defvar with-editor-envvars '("EDITOR" "GIT_EDITOR" "HG_EDITOR"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user