UndeadKernel / pacfiles-mode

Emacs major mode to manage pacnew and pacsave files left by the pacman Arch tool
MIT License
42 stars 2 forks source link

Release tag MIT license

pacfiles-mode

Emacs major mode to manage .pacnew and .pacsave files left by Arch's pacman. To merge files, pacfiles-mode automatically creates an Ediff merge session that a user can interact with. After finishing the Ediff merge session, pacfiles-mode cleans up the mess that Ediff leaves behind. pacfiles-mode also takes care of keeping the correct permissions of merged files, and requests passwords (with TRAMP) to act as root when needed.

pacfiles-mode is free software, licensed under the MIT License.

pacfiles-mode main interface

Installation and Setup

pacfiles-mode can be installed automatically from a package repository or manually.

Automatic installation

pacfiles-mode is in the MELPA package repository. To install from MELPA, make sure the following is somewhere in your ~/.emacs.d/init.el:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

Open emacs and execute M-x package-refresh-contents RET followed by M-x package-install RET pacfiles-mode RET. pacfiles-mode will then be compiled and installed.

Manual installation

To manually install pacfiles-mode, clone this repository into .emacs.d:

$ cd ~/.emacs.d
$ git clone https://github.com/UndeadKernel/pacfiles-mode.git

Then add the cloned folder to your load-path and require pacfiles-mode by adding the following to ~/.emacs.d/init.el:

(add-to-list 'load-path "~/.emacs.d/pacfiles-mode")
(require 'pacfiles-mode)

Overview

Start pacfiles-mode with the command pacfiles. Choose a file to merge by clicking (or pressing RET) on [merge]. An Ediff session will start; do not change the name of the Ediff buffers. After finishing the merging process, save the merged file (e.g., in Ediff's command buffer, use keybindings w c) without changing its name or location and quit Ediff. To apply the merge file to the file system, click (or press RET) on [apply]. Quit pacfiles-mode by pressing q.

Main interface

pacfiles-mode searches and lists all .pacnew and .pacsave update files found in /etc (by default). These update files can be discarded or, with the help of [Ediff](https://www.gnu.org/software/emacs/manual/html_node/ediff/ "Ediff's manual"), compared or merged. Ediff is automatically setup for the user; permissions are also taken care for.

Pending files

.pacnew or .pacsave file that have not been merged by the user are shown under the pending header. Three actions are available on these files

Pending Actions

If the [diff] button is not available, there is no base file to compare with. In this case, [merge] will treat the update, as is, as the file to merge.

Merged files

.pacnew and .pacsave files that have been merged, but not applied into the file system, are shown under the merged header. Three actions are available on these files:

Merged Actions

Apply or discard all changes

Apply/Discard All Actions

The [Apply All] and [Discard All] buttons do what you would expect them to do.

Ediff tricks and tips

When merging an update, Ediff's setup will look like this:

Ediff interface

Ediff's control buffer (on the bottom) will be focused and ready to receive user commands. The following key bindings are most useful:

When saving the merge buffer, do not change the merge buffer's location or name. You can switch to the merge buffer, buffer C in Ediff, and modify it as any other buffer.

Functions and Variables of pacfiles-mode

Commands

Configuration variables

Keybindings

What's happening in the back

When merging a .pacnew or .pacsave update with its corresponding base file, pacfiles-mode computes a hash of the base file. The hash is used to name a temporary merge file with the format<hash>.pacmerge. If pacfiles-mode finds a .pacmerge file whose name matches the hash of a base file, the .pacmerge file is associated to the base file as its merge. When applying a merge, this temporary .pacmerge file replaces the base file and the corresponding update file is deleted.