Skip to content

Commit

Permalink
Add debug defcustom
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescherti committed Aug 16, 2024
1 parent 6e1e368 commit a05cc54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The `local-config` Emacs package automatically loads and evaluates Elisp code fr

For instance, you can use the `local-config` package to:
- **Configure project-specific settings**: Automatically set up environment variables, keybindings, or modes unique to each project.
- **Apply directory-specific customizations**: Set specific behaviors or preferences for files in different directories, such as enabling or disabling certain minor modes based on security considerations. For example, you might disable linters or code executors in directories where you handle untrusted code.
- **Apply directory-specific customizations**: Set specific behaviors or preferences for files in different directories, such as enabling or disabling certain minor modes based on security considerations. For example, you might disable linters that execute code in directories where you handle untrusted code.
- **Manage multiple environments**: Switch between different coding environments or workflows by loading environment-specific configurations.

Features:
Expand Down
38 changes: 22 additions & 16 deletions local-config.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; local-config.el --- Automatically load local Emacs RC files -*- lexical-binding: t; -*-
;;; local-config.el --- Automatically load local Elisp config file -*- lexical-binding: t; -*-

;; Copyright (C) 2003-2024 James Cherti | https://www.jamescherti.com/contact/

Expand All @@ -23,7 +23,7 @@
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;; This `local-config` Emacs package facilitates the search and loading of local
;; This `local-config' Emacs package facilitates the search and loading of local
;; configuration files (`.emacs-local-config.el`) within the directory of the
;; buffer or its parent directories.
;;
Expand Down Expand Up @@ -69,7 +69,12 @@ file'."
:group 'local-config)

(defcustom local-config-verbose nil
"Enable verbose mode to log when a local Emacs RC file is loaded or ignored."
"Enable verbose mode to log when a local config file is loaded or ignored."
:type 'boolean
:group 'local-config)

(defcustom local-config-debug nil
"Enable debug mode to log when a local config file is loaded or ignored."
:type 'boolean
:group 'local-config)

Expand Down Expand Up @@ -104,18 +109,18 @@ otherwise."

(defun local-config-get-dir ()
"Return the directory of the currently loaded local config file.
Return `nil` if the local Emacs RC file has not been loaded."
Return `nil` if the local config file has not been loaded."
(when (bound-and-true-p local-config--dir)
local-config--dir))

(defun local-config-get-file ()
"Return the file of the currently loaded local config file.
Return `nil` if the local Emacs RC file has not been loaded."
Return `nil` if the local config file has not been loaded."
(when (bound-and-true-p local-config--file)
local-config--file))

(defun local-config-status ()
"Check if local Emacs RC have been loaded for the current buffer."
"Check if local config file have been loaded for the current buffer."
(interactive)
(if (and (bound-and-true-p local-config--dir)
(bound-and-true-p local-config--loaded))
Expand Down Expand Up @@ -156,10 +161,10 @@ FILE-NAMES. Returns the path to the found file or nil if none is found."
(let ((local-config-file (local-config-get-file)))
(if local-config-file
(find-file local-config-file)
(message "[local-config] The local Emacs RC file was not found."))))
(message "[local-config] The local Emacs config file was not found."))))

(defun local-config-load ()
"Load local Emacs RC file for CURRENT-FILE from the closest parent directory.
"Load local config file for CURRENT-FILE from the closest parent directory.
Only loads settings if the directory is allowed and not denied."
(setq-local local-config--loaded nil)
(setq-local local-config--allowed-p nil)
Expand Down Expand Up @@ -190,21 +195,22 @@ Only loads settings if the directory is allowed and not denied."
(setq-local local-config--loaded t)
(when local-config-verbose
(message "[local-config] Load: %s" local-config-file)))
(when local-config-verbose
(message "[local-config] Ignore: %s" local-config-file))))
(message (concat "[local-config] None of the local Emacs RC "
"files %s were found in '%s' "
"or one of its parents")
local-config-file-names
current-dir)))))
(when local-config-debug
(message "[local-config] Not allowed: %s" local-config-file))))
(when local-config-debug
(message (concat "[local-config] None of the local config "
"files %s were found in '%s' "
"or one of its parents")
local-config-file-names
current-dir))))))

;;;###autoload
(define-minor-mode local-config-mode
"Toggle `local-config-mode'.
When enabled, `local-config-mode' loads directory-specific settings
automatically."
:global t
:lighter " LEmacsRC"
:lighter " LocCfg"
:group 'local-config
(if local-config-mode
(add-hook 'find-file-hook #'local-config-load)
Expand Down

0 comments on commit a05cc54

Please sign in to comment.