2016-12-24 02:43:37 +00:00
|
|
|
;;; last-chance.el --- dangling deterrence -*- lexical-binding: t; -*-
|
|
|
|
|
2023-01-01 10:31:12 +00:00
|
|
|
;; Copyright (C) 2016-2023 Free Software Foundation, Inc.
|
2016-12-24 02:43:37 +00:00
|
|
|
|
|
|
|
;; Author: Thien-Thi Nguyen <ttn@gnu.org>
|
2019-05-25 20:43:06 +00:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
2016-12-24 02:43:37 +00:00
|
|
|
;; Keywords: maint
|
|
|
|
;; Package: emacs
|
|
|
|
|
|
|
|
;; 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
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2016-12-24 02:43:37 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Late 2016. In a recent build, the date in a ChangeLog file
|
2017-12-20 21:23:11 +00:00
|
|
|
;; is not fontified. Turns out the face `change-log-date-face'
|
2016-12-24 02:43:37 +00:00
|
|
|
;; was declared obsolete since 22.1 and removed 2016-06-23.
|
|
|
|
;; (compile "git show c430f7e23fc2c22f251ace4254e37dea1452dfc3")
|
|
|
|
;;
|
2017-12-20 21:23:11 +00:00
|
|
|
;; This library provides a command `last-chance', which is a small
|
2016-12-24 02:43:37 +00:00
|
|
|
;; combination of "git grep" and some regexp filtering. For example,
|
2017-12-20 21:23:11 +00:00
|
|
|
;; if point is on the symbol `change-log-date-face' in the form:
|
2016-12-24 02:43:37 +00:00
|
|
|
;;
|
|
|
|
;; (define-obsolete-face-alias 'change-log-date-face ...)
|
|
|
|
;;
|
|
|
|
;; then:
|
|
|
|
;;
|
|
|
|
;; M-x last-chance RET
|
|
|
|
;;
|
2017-12-20 21:23:11 +00:00
|
|
|
;; will show you any references to `change-log-date-face' in the
|
2016-12-24 02:43:37 +00:00
|
|
|
;; *.el files in a new buffer (in Grep mode). Hopefully you see
|
2022-11-20 11:59:39 +00:00
|
|
|
;; only the obsolete declaration and can proceed with its removal.
|
2016-12-24 02:43:37 +00:00
|
|
|
;; If not, please DTRT and refrain from the removal until those
|
|
|
|
;; references are properly transitioned.
|
|
|
|
;;
|
|
|
|
;; [Insert "nobody reads ChangeLog files" lament, here. --ttn]
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'grep)
|
|
|
|
(require 'thingatpt)
|
|
|
|
|
|
|
|
(defvar last-chance-grep-command "git grep -n -H -F -e"
|
|
|
|
"Command that ends in \"-e\" to do the \"git grep\".
|
|
|
|
This should include -n, -H, -F.")
|
|
|
|
|
|
|
|
(defvar last-chance-uninteresting-regexps
|
|
|
|
'("ChangeLog[.0-9]*:"
|
2016-12-30 06:13:17 +00:00
|
|
|
"NEWS[-.0-9]*:"
|
2017-12-20 21:23:11 +00:00
|
|
|
;; Add more `flush-lines' args here.
|
2016-12-24 02:43:37 +00:00
|
|
|
)
|
|
|
|
"List of regexps that match uninteresting \"git grep\" hits.")
|
|
|
|
|
|
|
|
(defvar-local last-chance-symbol nil
|
2017-12-20 21:23:11 +00:00
|
|
|
"Symbol set by `last-chance' for `last-chance-cleanup' to DTRT.")
|
2016-12-24 02:43:37 +00:00
|
|
|
|
|
|
|
(defun last-chance-cleanup (buffer status)
|
|
|
|
"Filter lines in BUFFER; append STATUS and count of removed lines.
|
2017-12-20 21:23:11 +00:00
|
|
|
If BUFFER does not seem to be one created by `last-chance', do nothing.
|
|
|
|
This function is intended to be added to `compilation-finish-functions'."
|
2016-12-24 02:43:37 +00:00
|
|
|
(let ((name (buffer-local-value 'last-chance-symbol buffer))
|
|
|
|
bef aft)
|
|
|
|
(when name
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(setq bef (count-lines (point-min) (point-max)))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward last-chance-grep-command)
|
|
|
|
(forward-line 1)
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(dolist (re last-chance-uninteresting-regexps)
|
|
|
|
(flush-lines re))
|
|
|
|
(keep-lines (format "\\_<%s\\_>" name)))
|
|
|
|
(setq aft (count-lines (point-min) (point-max)))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert (format "(status: %s, lines removed: %d)"
|
|
|
|
(car (split-string status "\n"))
|
|
|
|
(- bef aft)))))))
|
|
|
|
|
|
|
|
(defun last-chance (symbol)
|
|
|
|
"Grep the repo for SYMBOL, filtering the hits.
|
2017-12-20 21:23:11 +00:00
|
|
|
This uses `last-chance-grep-command' to do the grep and the
|
|
|
|
regexps in `last-chance-uninteresting-regexps' to filter the hits.
|
|
|
|
Grepping is recursive starting under the dir that `vc-root-dir'
|
|
|
|
finds (or the default directory if `vc-root-dir' finds nothing).
|
2016-12-24 02:43:37 +00:00
|
|
|
Output goes to the *grep* buffer.
|
|
|
|
|
|
|
|
Interactively, Emacs queries for a symbol,
|
|
|
|
defaulting to the one at point."
|
|
|
|
(interactive (list (read (let ((one (symbol-at-point)))
|
|
|
|
(when one
|
|
|
|
(setq one (symbol-name one)))
|
|
|
|
(completing-read
|
|
|
|
"Symbol: " obarray
|
|
|
|
nil nil
|
|
|
|
one nil one)))))
|
2021-01-03 22:25:06 +00:00
|
|
|
(with-current-buffer
|
|
|
|
(let ((default-directory (or (vc-root-dir)
|
|
|
|
default-directory)))
|
|
|
|
(grep (format "%s %s"
|
|
|
|
last-chance-grep-command
|
|
|
|
symbol)))
|
|
|
|
(add-hook 'compilation-finish-functions #'last-chance-cleanup nil t)
|
|
|
|
(setq-local last-chance-symbol symbol)))
|
2016-12-24 02:43:37 +00:00
|
|
|
|
|
|
|
(provide 'last-chance)
|
|
|
|
|
|
|
|
;;; last-chance.el ends here
|