Skip to content

Commit 180eea7

Browse files
committed
Prepare for MELPA submission
1 parent cdb6f72 commit 180eea7

5 files changed

Lines changed: 87 additions & 43 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ other buffer.
109109
## Functions and Variables
110110

111111
### Commands
112-
* `pacfiles` or `pacfiles/start`: start *pacfiles-mode*.
113-
* `pacfiles/quit`: quit *pacfiles-mode*.
114-
* `pacfiles/revert-buffer`: reload the list of update files
112+
* `pacfiles` or `pacfiles-start`: start *pacfiles-mode*.
113+
* `pacfiles-quit`: quit *pacfiles-mode*.
114+
* `pacfiles-revert-buffer`: reload the list of update files
115115

116116
### Configuration variables
117117
* `pacfiles-updates-search-command`: command used to search for `.pacnew` and

pacfiles-buttons.el

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
11
;;; pacfiles-buttons.el --- the buttons of pacfiles-mode --- -*- lexical-binding: t; -*-
22

33
;;; Commentary:
4+
;; Definitions that deal with buttons and their fonts.
5+
;;
46
;;; Code:
57

6-
(defgroup pacfiles-button-faces nil "Faces for the buttons used in pacfiles-mode.")
8+
(defgroup pacfiles-button-faces nil
9+
"Faces for the buttons used in pacfiles-mode."
10+
:group 'pacfiles)
711

8-
(defface pacfiles--apply-all-face
12+
(defface pacfiles--apply-all
913
'((t (:inherit 'button :height 1.3)))
1014
"Face for the Apply All button."
1115
:group 'pacfiles-button-faces)
1216

13-
(defface pacfiles--discard-all-face
17+
(defface pacfiles--discard-all
1418
'((t (:inherit 'button :height 1.3)))
1519
"Face for the Apply All button."
1620
:group 'pacfiles-button-faces)
1721

18-
(defface pacfiles--discard-face
22+
(defface pacfiles--discard
1923
'((t (:inherit 'warning :weight bold :underline t)))
2024
"Face for the Apply All button."
2125
:group 'pacfiles-button-faces)
2226

23-
(defface pacfiles--delete-face
27+
(defface pacfiles--delete
2428
'((t (:inherit 'error :weight bold :underline t)))
2529
"Face for the Apply All button."
2630
:group 'pacfiles-button-faces)
2731

2832

2933
(define-button-type 'pacfiles--button-apply-all
30-
'face 'pacfiles--apply-all-face
34+
'face 'pacfiles--apply-all
3135
'follow-link t)
3236

3337
(define-button-type 'pacfiles--button-discard-all
34-
'face 'pacfiles--discard-all-face
38+
'face 'pacfiles--discard-all
3539
'follow-link t)
3640

3741
(define-button-type 'pacfiles--button-apply
3842
'face 'button
3943
'follow-link t)
4044

4145
(define-button-type 'pacfiles--button-discard
42-
'face 'pacfiles--discard-face
46+
'face 'pacfiles--discard
4347
'follow-link t)
4448

4549
(define-button-type 'pacfiles--button-delete
46-
'face 'pacfiles--delete-face
50+
'face 'pacfiles--delete
4751
'follow-link t)
4852

4953
(define-button-type 'pacfiles--button-generic

pacfiles-mode.el

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1-
;;; pacfiles-mode.el --- Definition of the pacfiles Major mode -*- lexical-binding: t; -*-
2-
1+
;;; pacfiles-mode.el --- pacnew and pacsave merging tool -*- lexical-binding: t; -*-
2+
;;
3+
;; Copyright (C) 2018 Carlos G. Cordero
4+
;;
5+
;; Author: Carlos G. Cordero <http://github/UndeadKernel>
6+
;; Maintainer: Carlos G. Cordero <pacfiles@binarycharly.com>
7+
;; Created: Oct 11, 2018
8+
;; Modified: Oct 11, 2018
9+
;; Version: 1.0
10+
;; Keywords: files pacman arch pacnew pacsave update linux
11+
;; URL: https://github.com/UndeadKernel/pacfiles-mode
12+
;; Package-Requires: ((emacs "26") (cl-lib "0.5"))
13+
;;
14+
;; This file is not part of GNU Emacs.
15+
;;
316
;;; Commentary:
4-
;; The following coding conventions are used:
5-
;; pacfiles/ : User facing (public) function
6-
;; pacfiles- : User facing (public) variable
7-
;; pacfiles-- : Private function or variable
17+
;;
18+
;; `pacfiles-mode' is an Emacs major mode to manage `.pacnew` and `.pacsave`
19+
;; files left by Arch's pacman. To merge files, *pacfiles-mode* automatically
20+
;; creates an Ediff merge session that a user can interact with. After finishing
21+
;; the Ediff merge session, *pacfiles-mode* cleans up the mess that Ediff leaves
22+
;; behind. *pacfiles-mode* also takes care of keeping the correct permissions of
23+
;; merged files, and requests passwords (with TRAMP) to act as root when needed.
24+
;;
25+
;; Start the major mode using the command `pacfiles' or `pacfiles/start'.
26+
;;
827
;;; Code:
928

1029
(require 'pacfiles-buttons)
1130
(require 'pacfiles-utils)
1231
(require 'pacfiles-win)
1332

33+
(require 'cl-seq)
34+
(require 'ediff)
35+
(require 'outline)
36+
(require 'time-date)
37+
38+
(defgroup pacfiles nil "Faces for the buttons used in pacfiles-mode."
39+
:group 'tools)
1440

1541
(defvar pacfiles-updates-search-command "find /etc -name '*.pacnew' -o -name '*.pacsave' 2>/dev/null"
1642
"Command to find .pacnew files.")
@@ -23,8 +49,11 @@
2349
"Alist that stores ediff variables and its values.")
2450

2551

26-
(defalias 'pacfiles 'pacfiles/start)
27-
(defun pacfiles/start ()
52+
;;;###autoload
53+
(defalias 'pacfiles 'pacfiles-start)
54+
55+
;;;###autoload
56+
(defun pacfiles-start ()
2857
"Find and manage pacman backup files in an Arch-based GNU/Linux system."
2958
(interactive)
3059
;; Save the current window configuration so that it can be restored when we are finished.
@@ -35,19 +64,19 @@
3564
(display-buffer buffer '(pacfiles--display-buffer-fullscreen))
3665
(with-current-buffer buffer
3766
(pacfiles-mode)
38-
(pacfiles/revert-buffer t t))))
67+
(pacfiles-revert-buffer t t))))
3968

40-
(defun pacfiles/quit ()
41-
"Quit pacfiles-mode and restore the previous window configuration."
69+
(defun pacfiles-quit ()
70+
"Quit pacfiles-mode and restore the previous window and ediff configuration."
4271
(interactive)
4372
(pacfiles--restore-ediff-conf)
4473
;; Kill buffers we create which start with '*pacfiles:'
4574
(kill-matching-buffers "^\\*pacfiles:.*" t t)
4675
(pacfiles--pop-window-conf))
4776

4877
;; Main function that displays the contents of the PACFILES buffer.
49-
(defun pacfiles/revert-buffer (&optional ignore-auto noconfirm)
50-
"Populate the pacfiles-mode buffer with .pacnew and .pacsave files.
78+
(defun pacfiles-revert-buffer (&optional _ignore-auto noconfirm)
79+
"Populate the pacfiles-mode buffer with .pacnew and .pacsave files.
5180
5281
Ignore IGNORE-AUTO but take into account NOCONFIRM."
5382
(interactive)
@@ -92,17 +121,18 @@ Ignore IGNORE-AUTO but take into account NOCONFIRM."
92121
(pacfiles--insert-footer-buttons))))
93122
(goto-char 0))
94123

95-
(defun pacfiles/revert-buffer-no-confirm ()
124+
;;;###autoload
125+
(defun pacfiles-revert-buffer-no-confirm ()
96126
"Revert the pacfiles list buffer without asking for confirmation."
97127
(interactive)
98-
(pacfiles/revert-buffer t t))
128+
(pacfiles-revert-buffer t t))
99129

100130
(defun pacfiles--insert-pending-files (files-alist merged-files)
101131
"Insert files in FILES-ALIST if their `cdr' is not in MERGED-FILES.
102132
103133
The FILE-TYPE specifies which type of update file we are processing."
104134
;; Keep files in FILES-ALIST which don't have a cdr in MERGED-FILES.
105-
(let ((pending-alist (remove-if (lambda (i) (member (cdr i) merged-files)) files-alist)))
135+
(let ((pending-alist (cl-remove-if (lambda (i) (member (cdr i) merged-files)) files-alist)))
106136
(if (null pending-alist)
107137
(insert (propertize "--- no pending files ---\n" 'font-lock-face 'font-lock-comment-face))
108138
(dolist (file-pair pending-alist)
@@ -115,9 +145,9 @@ The FILE-TYPE specifies which type of update file we are processing."
115145

116146
(defun pacfiles--insert-merged-files (files-alist merged-files)
117147
"Insert files in FILES-ALIST that have an associated file in MERGED-FILES."
118-
(let ((merged-alist (remove-if-not (lambda (i) (member (cdr i) merged-files)) files-alist)))
148+
(let ((merged-alist (cl-remove-if-not (lambda (i) (member (cdr i) merged-files)) files-alist)))
119149
(if (null merged-alist)
120-
(insert (propertize "--- no merge files ---\n" 'font-lock-face 'font-lock-comment-face))
150+
(insert (propertize "--- no merged files ---\n" 'font-lock-face 'font-lock-comment-face))
121151
(dolist (file-pair merged-alist)
122152
(pacfiles--insert-apply-button file-pair)
123153
(pacfiles--insert-view-merge-button file-pair)
@@ -160,7 +190,7 @@ If REVERSE-ORDER is non-nil, calculate the time difference as
160190

161191
(defun pacfiles--save-ediff-conf ()
162192
"Save ediff variables we modify with the user's current values.
163-
We restore the saved variables after pacfiles-mode quits."
193+
We restore the saved variables after pacfiles-mode quits."
164194
(require 'ediff)
165195
(let ((vars-to-save
166196
'(ediff-autostore-merges ediff-keep-variants ediff-window-setup-function
@@ -170,7 +200,7 @@ We restore the saved variables after pacfiles-mode quits."
170200
(push (pacfiles--var-to-cons var) pacfiles--ediff-conf))))
171201

172202
(defun pacfiles--change-ediff-conf ()
173-
"Change ediff's configuration variables to fit pacfiles-mode."
203+
"Change ediff's configuration variables to fit pacfiles-mode."
174204
(setq ediff-autostore-merges nil
175205
ediff-keep-variants t
176206
ediff-window-setup-function #'ediff-setup-windows-plain
@@ -179,7 +209,7 @@ We restore the saved variables after pacfiles-mode quits."
179209
(add-hook 'ediff-quit-hook #'pacfiles--pop-window-conf t)
180210
(add-hook 'ediff-cleanup-hook #'pacfiles--clean-after-ediff)
181211
(remove-hook 'ediff-quit-merge-hook #'ediff-maybe-save-and-delete-merge)
182-
(add-hook 'ediff-quit-hook (lambda () (pacfiles/revert-buffer t t))))
212+
(add-hook 'ediff-quit-hook (lambda () (pacfiles-revert-buffer t t))))
183213

184214
(defun pacfiles--restore-ediff-conf ()
185215
"Restore the ediff variables saved by `pacfiles--save-ediff-conf'."
@@ -189,25 +219,29 @@ We restore the saved variables after pacfiles-mode quits."
189219

190220
(defvar pacfiles-mode-map
191221
(let ((map (make-sparse-keymap)))
192-
(define-key map (kbd "q") #'pacfiles/quit)
193-
(define-key map (kbd "g") #'pacfiles/revert-buffer-no-confirm)
194-
(define-key map (kbd "r") #'pacfiles/revert-buffer-no-confirm)
222+
(define-key map (kbd "q") #'pacfiles-quit)
223+
(define-key map (kbd "g") #'pacfiles-revert-buffer-no-confirm)
224+
(define-key map (kbd "r") #'pacfiles-revert-buffer-no-confirm)
195225
(define-key map (kbd "TAB") #'outline-toggle-children)
196226
(define-key map (kbd "C-c C-p") #'outline-previous-heading)
197227
(define-key map (kbd "C-c C-n") #'outline-next-heading)
198228
(define-key map (kbd "n") #'forward-button)
199229
(define-key map (kbd "p") #'backward-button)
200230
map)
201-
"Keymap for pacfiles-mode.")
231+
"Keymap for ‘pacfiles-mode’.")
232+
233+
;; Tell emacs that, when creating new buffers, pacfiles-mode should not be used
234+
;; ... as the major mode.
235+
(put 'pacfiles-mode 'mode-class 'special)
202236

237+
;;;###autoload
203238
(define-derived-mode pacfiles-mode outline-mode "pacfiles"
204239
:syntax-table nil
205240
:abbrev-table nil
206241
"Major mode for managing .pacnew and .pacsave files."
207242
;; If the buffer is not the one we create, do nothing and error out.
208-
(when (not (string= (buffer-name) pacfiles--files-buffer-name))
209-
(user-error "Use the command `pacfiles' instead of `pacfiles-mode' to start pacfiles-mode")
210-
(return))
243+
(unless (string= (buffer-name) pacfiles--files-buffer-name)
244+
(user-error "Use the command `pacfiles' instead of `pacfiles-mode' to start pacfiles-mode"))
211245
;; The buffer shall not be edited.
212246
(read-only-mode)
213247
;; No edits... no undo.
@@ -224,7 +258,8 @@ We restore the saved variables after pacfiles-mode quits."
224258
(when (and (fboundp 'display-line-numbers-mode)
225259
(bound-and-true-p global-display-line-numbers-mode))
226260
(display-line-numbers-mode -1))
227-
(setq-local revert-buffer-function #'pacfiles/revert-buffer)
261+
;; Set the function used when reverting pacfile-mode buffers.
262+
(setq-local revert-buffer-function #'pacfiles-revert-buffer)
228263
;; configure ediff
229264
(pacfiles--change-ediff-conf)
230265
;; configure outline-mode

pacfiles-utils.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
;;; pacfiles-utils.el --- common utilities of pacfiles-mode -*- lexical-binding: t; -*-
22

3-
;;; Code:
43
;;; Commentary:
4+
;; Utility functions used throughout pacfiles-mode
5+
;;
6+
;;; Code:
57

68
(defun pacfiles--calculate-merge-file (file path)
79
"File name associated to the merge file tied to FILE located in PATH."
@@ -22,7 +24,7 @@ PERMISSION is either \":read\" or \":write\""
2224
apt-path))
2325

2426
(defun pacfiles--var-to-cons (var)
25-
"Create a cons of the VAR symbol and the value of VAR."
27+
"Create a cons of the VAR symbol and the VAR value."
2628
`(,var . ,(symbol-value var)))
2729

2830
(defun pacfiles--cons-to-var (cons)

pacfiles-win.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
;;; pacfiles-win.el --- Window related functions -*- lexical-binding: t; -*-
22

33
;;; Commentary:
4+
;; Functions to manage the windows of pacfiles-mode
5+
;;
46
;;; Code:
57

68
(require 'subr-x)
9+
(require 'ediff)
710

811
(defvar pacfiles--files-buffer-name "*pacfiles:file-list*"
912
"Name of the window that holds the list of pacman files.")

0 commit comments

Comments
 (0)