aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2016-12-24 03:43:37 +0100
committerThien-Thi Nguyen2016-12-24 03:43:37 +0100
commit9227b5ce0c0e9a52bcce58673cc246cb9ca4b3d1 (patch)
tree5a955dbaa09a1c2cec04fd231758a7d3d32a81a2
parente2767bd010d5c30df97789b8b56a42eff4234e5b (diff)
downloademacs-9227b5ce0c0e9a52bcce58673cc246cb9ca4b3d1.tar.gz
emacs-9227b5ce0c0e9a52bcce58673cc246cb9ca4b3d1.zip
last-chance: new utility lib for dangling deterrence
* admin/last-chance.el: New file.
-rw-r--r--admin/last-chance.el122
1 files changed, 122 insertions, 0 deletions
diff --git a/admin/last-chance.el b/admin/last-chance.el
new file mode 100644
index 00000000000..5151a7562dd
--- /dev/null
+++ b/admin/last-chance.el
@@ -0,0 +1,122 @@
1;;; last-chance.el --- dangling deterrence -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2000-2016 Free Software Foundation, Inc.
4
5;; Author: Thien-Thi Nguyen <ttn@gnu.org>
6;; Maintainer: emacs-devel@gnu.org
7;; Keywords: maint
8;; Package: emacs
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software: you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25;;; Commentary:
26
27;; Late 2016. In a recent build, the date in a ChangeLog file
28;; is not fontified. Turns out the face ‘change-log-date-face’
29;; was declared obsolete since 22.1 and removed 2016-06-23.
30;; (compile "git show c430f7e23fc2c22f251ace4254e37dea1452dfc3")
31;;
32;; This library provides a command ‘last-chance’, which is a small
33;; combination of "git grep" and some regexp filtering. For example,
34;; if point is on the symbol ‘change-log-date-face’ in the form:
35;;
36;; (define-obsolete-face-alias 'change-log-date-face ...)
37;;
38;; then:
39;;
40;; M-x last-chance RET
41;;
42;; will show you any references to ‘change-log-date-face’ in the
43;; *.el files in a new buffer (in Grep mode). Hopefully you see
44;; only the obsolete declaration and can proceed w/ its removal.
45;; If not, please DTRT and refrain from the removal until those
46;; references are properly transitioned.
47;;
48;; [Insert "nobody reads ChangeLog files" lament, here. --ttn]
49
50;;; Code:
51
52(require 'grep)
53(require 'thingatpt)
54
55(defvar last-chance-grep-command "git grep -n -H -F -e"
56 "Command that ends in \"-e\" to do the \"git grep\".
57This should include -n, -H, -F.")
58
59(defvar last-chance-uninteresting-regexps
60 '("ChangeLog[.0-9]*:"
61 ;; Add more ‘flush-lines’ args here.
62 )
63 "List of regexps that match uninteresting \"git grep\" hits.")
64
65(defvar-local last-chance-symbol nil
66 "Symbol set by ‘last-chance’ for ‘last-chance-cleanup’ to DTRT.")
67
68(defun last-chance-cleanup (buffer status)
69 "Filter lines in BUFFER; append STATUS and count of removed lines.
70If BUFFER is not seem to be one created by ‘last-chance’, do nothing.
71This function is intended to be added to ‘compilation-finish-functions’."
72 (let ((name (buffer-local-value 'last-chance-symbol buffer))
73 bef aft)
74 (when name
75 (with-current-buffer buffer
76 (setq bef (count-lines (point-min) (point-max)))
77 (goto-char (point-min))
78 (search-forward last-chance-grep-command)
79 (forward-line 1)
80 (let ((inhibit-read-only t))
81 (dolist (re last-chance-uninteresting-regexps)
82 (flush-lines re))
83 (keep-lines (format "\\_<%s\\_>" name)))
84 (setq aft (count-lines (point-min) (point-max)))
85 (goto-char (point-max))
86 (insert (format "(status: %s, lines removed: %d)"
87 (car (split-string status "\n"))
88 (- bef aft)))))))
89
90(defun last-chance (symbol)
91 "Grep the repo for SYMBOL, filtering the hits.
92This uses ‘last-chance-grep-command’ to do the grep and the
93regexps in ‘last-chance-uninteresting-regexps’ to filter the hits.
94Grepping is recursive starting under the dir that ‘vc-root-dir’
95finds (or the default directory if ‘vc-root-dir’ finds nothing).
96Output goes to the *grep* buffer.
97
98Interactively, Emacs queries for a symbol,
99defaulting to the one at point."
100 (interactive (list (read (let ((one (symbol-at-point)))
101 (when one
102 (setq one (symbol-name one)))
103 (completing-read
104 "Symbol: " obarray
105 nil nil
106 one nil one)))))
107 (let ((default-directory (or (vc-root-dir)
108 default-directory)))
109 (grep (format "%s %s"
110 last-chance-grep-command
111 symbol)))
112 (setf (buffer-local-value 'last-chance-symbol
113 (process-buffer
114 (car compilation-in-progress)))
115 symbol))
116
117(add-to-list 'compilation-finish-functions
118 'last-chance-cleanup)
119
120(provide 'last-chance)
121
122;;; last-chance.el ends here