Skip to content

Commit a21d66f

Browse files
committed
docs(core): better documentation and comments
1 parent fa44fa3 commit a21d66f

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

elisp/ecryptfs.el

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; -*- lexical-binding: t; -*-
1+
;; ecryptfs.el -- eCryptfs integration -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2022-2023 Abdelhak Bougouffa
44

@@ -8,19 +8,20 @@
88

99
;; This allows me to mount my private directory encrypted using ecryptfs-utils.
1010
;; It is a port of "ecryptfs-mount-private" shell command. It extracts the
11-
;; encryption key from a GPG encrypted file containting the ecryptfs password.
11+
;; encryption key from a GPG encrypted file containing the eCryptfs password.
1212
;; The decryption of the password is performed using Emacs' `epg'.
1313

1414
;;; Code:
1515

1616
(require 'epg)
17+
(autoload 'cl-every "cl-extras")
1718

1819
(defgroup minemacs-ecryptfs nil
1920
"MinEmacs eCryptfs."
2021
:group 'minemacs)
2122

2223
(defcustom ecryptfs-private-dir-name "Private"
23-
"eCryptfs private directory name."
24+
"The eCryptfs private directory name."
2425
:group 'minemacs-ecryptfs
2526
:type 'string)
2627

@@ -29,21 +30,26 @@
2930
:group 'minemacs-ecryptfs
3031
:type 'directory)
3132

32-
(defcustom ecryptfs-passphrase-file (concat ecryptfs-root-dir "my-pass.gpg")
33-
"GPG encrypted file containing eCryptfs password.")
33+
(defcustom ecryptfs-passphrase-file (concat ecryptfs-root-dir "password.gpg")
34+
"GPG encrypted file containing eCryptfs password."
35+
:group 'minemacs-ecryptfs
36+
:type 'file)
3437

3538
(defvar ecryptfs-buffer-name " *emacs-ecryptfs*")
3639
(defvar ecryptfs-process-name "emacs-ecryptfs")
3740
(defvar ecryptfs--mount-private-cmd "/sbin/mount.ecryptfs_private")
3841
(defvar ecryptfs--umount-private-cmd "/sbin/umount.ecryptfs_private")
3942

4043
(defun ecryptfs--wrapped-passphrase-file ()
44+
"Return eCryptfs' wrapped passphrase file path."
4145
(concat ecryptfs-root-dir "wrapped-passphrase"))
4246

4347
(defun ecryptfs--mount-passphrase-sig-file ()
48+
"Return eCryptfs' wrapped passphrase signature file path."
4449
(concat ecryptfs-root-dir ecryptfs-private-dir-name ".sig"))
4550

4651
(defun ecryptfs--passphrase ()
52+
"Return eCryptfs' passphrase from the GPG encrypted password file."
4753
(string-trim-right
4854
(epg-decrypt-file
4955
(epg-make-context)
@@ -52,25 +58,29 @@
5258
"[\n\r]+"))
5359

5460
(defun ecryptfs--encrypt-filenames-p ()
61+
"Des eCryptfs is configured with encrypted file names."
5562
(/= 1 (with-temp-buffer
5663
(insert-file-contents (ecryptfs--mount-passphrase-sig-file))
5764
(count-lines (point-min) (point-max)))))
5865

5966
(defun ecryptfs-available-p ()
67+
"Is eCryptfs available on the current system?"
6068
(and (file-directory-p (expand-file-name ecryptfs-private-dir-name "~"))
6169
(cl-every #'file-exists-p (list ecryptfs--mount-private-cmd
6270
ecryptfs--umount-private-cmd
6371
(ecryptfs--wrapped-passphrase-file)
6472
(ecryptfs--mount-passphrase-sig-file)))))
6573

6674
(defun ecryptfs--unwrap-passphrase-command ()
75+
"Return eCryptfs' command that unwraps the passphrase."
6776
(format
6877
(if (ecryptfs--encrypt-filenames-p)
6978
"ecryptfs-insert-wrapped-passphrase-into-keyring %s '%s'"
7079
"ecryptfs-unwrap-passphrase %s '%s' | ecryptfs-add-passphrase -")
7180
(ecryptfs--wrapped-passphrase-file) (ecryptfs--passphrase)))
7281

7382
(defun ecryptfs-private-mounted-p ()
83+
"Is eCryptfs' private directory is mounted?"
7484
(let ((mount (shell-command-to-string "mount")))
7585
(and (string-match-p (concat ".*" (expand-file-name ecryptfs-private-dir-name "~") ".*ecryptfs.*") mount)
7686
t)))
@@ -100,7 +110,7 @@
100110
(prog1 try-again (setq try-again nil)))
101111
(if (zerop (shell-command (ecryptfs--unwrap-passphrase-command) ecryptfs-buffer-name))
102112
(message "Successfully mounted private directory.")
103-
(user-error "A problem occured while mounting the private directory, see %s"
113+
(user-error "A problem occurred while mounting the private directory, see %s"
104114
ecryptfs-buffer-name))))))
105115

106116
;;;###autoload

elisp/netextender.el

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mandatory stored as a GPG encrypted file."
3131
:group 'minemacs-netextender
3232
:type '(choice string file))
3333

34-
(defcustom netextender-launcher-command (concat minemacs-local-dir "netextender-launcher.sh")
34+
(defcustom netextender-launcher-command (locate-user-emacs-file "netextender-launcher.sh")
3535
"Custom NetExtender launcher command.
3636
3737
This is a wrapper around the \"NetExtender\" command. It starts the sessions
@@ -50,19 +50,18 @@ temporary based on `netextender-command' and `netextender-passphrase-file' and
5050
returns it."
5151
;; If the command doesn't exist, generate it.
5252
(if (not (executable-find netextender-command))
53-
(user-error "The NetExtender command \"%s\" is not available." netextender-command)
53+
(user-error "The NetExtender command \"%s\" is not available" netextender-command)
5454
(unless (executable-find netextender-launcher-command)
5555
(setq netextender-launcher-command (make-temp-file "netextender-launcher-" nil ".sh"))
5656
(set-file-modes netextender-launcher-command #o755) ;; Make it executable
57-
(with-temp-buffer
58-
(insert (format "#!/bin/bash
57+
(with-temp-buffer (insert (format "#!/bin/bash
5958
6059
MY_LOGIN_PARAMS_FILE=\"%s\"
6160
6261
echo \"Y\\n\" | %s --auto-reconnect $(gpg -q --for-your-eyes-only --no-tty -d \"${MY_LOGIN_PARAMS_FILE}\")"
63-
(expand-file-name netextender-passphrase-file)
64-
(executable-find netextender-command)))
65-
(write-file netextender-launcher-command)))
62+
(expand-file-name netextender-passphrase-file)
63+
(executable-find netextender-command)))
64+
(write-file netextender-launcher-command)))
6665
;; Return the command
6766
netextender-launcher-command))
6867

@@ -73,7 +72,7 @@ echo \"Y\\n\" | %s --auto-reconnect $(gpg -q --for-your-eyes-only --no-tty -d \"
7372
;; pppd must be run as root (via setuid)
7473
(if (and pppd-modes (zerop (logand (lsh 1 11) pppd-modes))) ;; Check if the setuid bit isn't set
7574
(prog1 nil ;; return nil
76-
(user-error "pppd needs root permissions, please set the setuid bit of %s." pppd-command))
75+
(user-error "The `pppd' command needs root permissions, please set the setuid bit of %s" pppd-command))
7776
t)))
7877

7978
;;;###autoload
@@ -86,8 +85,8 @@ echo \"Y\\n\" | %s --auto-reconnect $(gpg -q --for-your-eyes-only --no-tty -d \"
8685
:buffer netextender-buffer-name
8786
:command (list (netextender-launcher-command)))
8887
(message "Started NetExtender VPN session.")
89-
(user-error "Cannot start NetExtender.")))
90-
(user-error "Cannot start a netExtender VPN session.")))
88+
(user-error "Cannot start NetExtender")))
89+
(user-error "Cannot start a netExtender VPN session")))
9190

9291
(defun netextender-kill ()
9392
"Kill the created NetExtender VPN session."
@@ -96,7 +95,7 @@ echo \"Y\\n\" | %s --auto-reconnect $(gpg -q --for-your-eyes-only --no-tty -d \"
9695
(if netextender-process
9796
(if (kill-process netextender-process)
9897
(message "Killed NetExtender VPN session.")
99-
(user-error "Cannot kill NetExtender."))
98+
(user-error "Cannot kill NetExtender"))
10099
(message "No running NetExtender session."))))
101100

102101
;;;###autoload

elisp/valgrind.el

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@
99
;;; Code:
1010

1111
(require 'compile)
12+
(require 'project)
13+
(eval-when-compile (require 'savehist))
1214

1315
(defgroup valgrind nil
1416
"Run valgrind as inferior of Emacs, parse error messages."
1517
:group 'tools
1618
:group 'processes)
1719

1820
(defcustom valgrind-command "valgrind --leak-check=full "
19-
"*Last shell command used to run valgrind; default for next valgrind run.
21+
"Last shell command used to run valgrind; default for next valgrind run.
2022
Sometimes it is useful for files to supply local values for this variable.
2123
You might also use mode hooks to specify it in certain modes, like this:
22-
(add-hook 'c-mode-hook
24+
(add-hook \\='c-mode-hook
2325
(lambda ()
2426
(unless (or (file-exists-p \"makefile\")
2527
(file-exists-p \"Makefile\"))
26-
(set (make-local-variable 'valgrind-command)
28+
(set (make-local-variable \\='valgrind-command)
2729
(concat \"make -k \"
2830
(file-name-sans-extension buffer-file-name))))))"
2931
:type 'string
@@ -39,10 +41,10 @@ You might also use mode hooks to specify it in certain modes, like this:
3941
;;;###autoload
4042
(defun valgrind (command)
4143
"Run valgrind.
42-
Runs COMMAND, a shell command, in a separate process asynchronously
43-
with output going to the buffer `*valgrind*'.
44-
You can then use the command \\[next-error] to find the next error message
45-
and move to the source code that caused it."
44+
Runs a shell COMMAND in a separate process asynchronously with output going to
45+
the buffer `*valgrind*'.
46+
You can then use the command \\[next-error] to find the next error message and
47+
move to the source code that caused it."
4648
(interactive
4749
(if (or compilation-read-command current-prefix-arg)
4850
(list (read-from-minibuffer "Valgrind command: "
@@ -52,7 +54,7 @@ and move to the source code that caused it."
5254
(let ((default-directory (or (project-root (project-current)) default-directory)))
5355
(unless (equal command (eval valgrind-command))
5456
(setq valgrind-command command))
55-
(compilation-start command nil (lambda (mode) "*valgrind*"))))
57+
(compilation-start command nil (lambda (_) "*valgrind*"))))
5658

5759

5860
(provide 'valgrind)

init.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@
114114
;; some new features when configuring them.
115115
(when (< emacs-major-version 29)
116116
(let ((backports-dir (concat minemacs-core-dir "backports/")))
117-
(mapc (apply-partially #'+load backports-dir) (directory-files backports-dir nil "\\.el$"))))
117+
(mapc (apply-partially #'+load backports-dir) (directory-files backports-dir nil "\\.el\\'"))))
118118

119119
(setq
120120
;; Enable debugging on error when Emacs is launched with the "--debug-init"
121121
;; option or when the environment variable "$MINEMACS_DEBUG" is defined (see
122122
;; `me-vars').
123123
debug-on-error minemacs-debug-p
124-
;; Decrese the warning type to `:error', unless we are running in verbose mode
124+
;; Decrease the warning type to `:error', unless we are running in verbose mode
125125
warning-minimum-level (if minemacs-verbose-p :warning :error)
126126
warning-minimum-log-level warning-minimum-level
127127
;; Make byte compilation less noisy

0 commit comments

Comments
 (0)