-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
recentf-excl.el
120 lines (93 loc) · 3.57 KB
/
recentf-excl.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
;;; recentf-excl.el --- Exclude commands for recent files -*- lexical-binding: t; -*-
;; Copyright (C) 2022-2024 Shen, Jen-Chieh
;; Created date 2022-05-23 19:01:51
;; Author: Shen, Jen-Chieh <jcs090218@gmail.com>
;; URL: https://github.com/jcs-elpa/recentf-excl
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1") (msgu "0.1.0"))
;; Keywords: convenience excl exclude recentf
;; This file is NOT part of GNU Emacs.
;; 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:
;;
;; Exclude commands for recent files
;;
;;; Code:
(require 'msgu)
(defgroup recentf-excl nil
"Exclude commands for recent files."
:prefix "recentf-excl-"
:group 'convenience
:group 'tools
:link '(url-link :tag "Repository" "https://github.com/jcs-elpa/recentf-excl"))
(defcustom recentf-excl-commands nil
"List of commands to ignore recent files."
:type 'list
:group 'recentf-excl)
;;;###autoload
(defvar recentf-excl-tracking-p t
"If non-nil, track the opened file.")
;;
;;; Util
(defun recentf-excl--re-enable-mode (modename)
"Re-enable the MODENAME."
(msgu-silent
(funcall-interactively modename -1) (funcall-interactively modename 1)))
(defun recentf-excl--re-enable-mode-if-was-enabled (modename)
"Re-enable the MODENAME if was enabled."
(when (boundp modename)
(when (symbol-value modename) (recentf-excl--re-enable-mode modename))
(symbol-value modename)))
(defun recentf-excl--listify (obj)
"Turn OBJ to list."
(if (listp obj) obj (list obj)))
;;
;;; Core
;;;###autoload
(defmacro recentf-excl-it (&rest body)
"Execute BODY and ignore recent files."
(declare (indent 0) (debug t))
`(let (recentf-excl-tracking-p) ,@body))
(defun recentf-excl--adv-around (fnc &rest args)
"Advice bind FNC and ARGS."
(recentf-excl-it (apply fnc args)))
(defun recentf-excl--track-opened-file (fnc &rest args)
"Control of track opened file.
Advice arguments FNC and ARGS."
(when recentf-excl-tracking-p (apply fnc args)))
(defun recentf-excl-mode--enable ()
"Enable function `recentf-excl-mode'."
(advice-add 'recentf-track-opened-file :around #'recentf-excl--track-opened-file)
(dolist (command recentf-excl-commands)
(advice-add command :around #'recentf-excl--adv-around)))
(defun recentf-excl-mode--disable ()
"Disable function `recentf-excl-mode'."
(advice-remove 'recentf-track-opened-file #'recentf-excl--track-opened-file)
(dolist (command recentf-excl-commands)
(advice-remove command #'recentf-excl--adv-around)))
;;;###autoload
(define-minor-mode recentf-excl-mode
"Minor mode `recentf-excl-mode'."
:global t
:require 'recentf-excl-mode
:group 'recentf-excl
(if recentf-excl-mode (recentf-excl-mode--enable) (recentf-excl-mode--disable)))
;;
;;; Users
;;;###autoload
(defun recentf-excl-add-commands (command)
"Add COMMAND to exclude list."
(let ((commands (recentf-excl--listify command)))
(nconc recentf-excl-commands commands)
(recentf-excl--re-enable-mode-if-was-enabled #'recentf-excl-mode)))
(provide 'recentf-excl)
;;; recentf-excl.el ends here