Skip to content

Commit

Permalink
Replace .local-config.el with .emacs-local-config.el
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescherti committed Aug 16, 2024
1 parent d0f1b3f commit 1fd3c39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
![Build Status](https://github.com/jamescherti/local-config.el/actions/workflows/ci.yml/badge.svg)
![License](https://img.shields.io/github/license/jamescherti/local-config.el)

This `local-config` Emacs package facilitates the search and loading of local configuration files (`.local-config.el`) within the directory of the buffer or its parent directories.
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.

Features:
- Automatic Configuration Discovery: Searches for and loads `.local-config.el` file from the
directory of the current buffer and its parent directories.
- Automatic Configuration Discovery: Searches for and loads `.emacs-local-config.el` file from the
directory of the current buffer or its parent directories.
- Selective Directory Loading: Restricts the loading of configuration files to directories listed in the variable `local-config-allowed-directories` and `local-config-denied-directories`, ensuring control over where configuration files are sourced from.
- The `local-config-mode` mode: Automatically loads the `.local-config.el` file whenever a file is opened, leveraging the `find-file-hook` to ensure that local configurations are applied.
- The `local-config-mode` mode: Automatically loads the `.emacs-local-config.el` file whenever a file is opened, leveraging the `find-file-hook` to ensure that local configurations are applied.

## Installation

Expand All @@ -28,7 +28,7 @@ To install the `local-config` using `straight.el`:
:repo "jamescherti/local-config.el")
:custom
(local-config-verbose t)
(local-config-filename ".local-config.el")
(local-config-file-names '(".emacs-local-config.el"))
(local-config-allowed-directories '("~/src" "~/projects"))
(local-config-denied-directories '("~/src/excluded_dir"))
:config
Expand All @@ -42,9 +42,9 @@ Assuming that the `local-config-dir` package has been configured to allow loadin
(setq local-config-allowed-directories '("~/src" "~/projects"))
```

Adding the following code to the `~/src/my_python_project/.local-config.el` file can modify the `PYTHONPATH` environment variable for Python buffers within its directory or one of its subdirectories (e.g., `~/src/my_python_project/my_python_project/file.py`). Modifying `PYTHONPATH` ensures that processes executed by tools like Flycheck or Flymake have access to the Python project's modules:
Adding the following code to the `~/src/my_python_project/.emacs-local-config.el` file can modify the `PYTHONPATH` environment variable for Python buffers within its directory or one of its subdirectories (e.g., `~/src/my_python_project/my_python_project/file.py`). Modifying `PYTHONPATH` ensures that processes executed by tools like Flycheck or Flymake have access to the Python project's modules:
``` emacs-lisp
;;; .local-config.el --- Local Emacs RC -*- no-byte-compile: t; lexical-binding: t; -*-
;;; .emacs-local-config.el --- Local Emacs RC -*- no-byte-compile: t; lexical-binding: t; -*-
(when (or (derived-mode-p 'python-ts-mode) (derived-mode-p 'python-mode))
(let ((python-path (getenv "PYTHONPATH"))
Expand All @@ -55,9 +55,9 @@ Adding the following code to the `~/src/my_python_project/.local-config.el` file
(concat ":" python-path)))))))
```

It is recommended to always begin your `.local-config.el` files with the following header:
It is recommended to always begin your `.emacs-local-config.el` files with the following header:
```
;;; .local-config.el --- Local Emacs RC -*- no-byte-compile: t; lexical-binding: t; -*-
;;; .emacs-local-config.el --- Local Emacs RC -*- no-byte-compile: t; lexical-binding: t; -*-
```

The `local-config-dir` package allows for automatic application of specific configurations based on the directory of the files being accessed, enhancing the flexibility and customization of the Emacs environment.
Expand Down
39 changes: 22 additions & 17 deletions local-config.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;; The `local-config' package automates the loading of Emacs configuration
;; files from '.local-config.el' files, allowing users to efficiently manage
;; settings for various projects or workspaces.
;; 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.
;;
;; Features:
;; - Recursive Search: Finds and loads '.local-config.el' files from the
;; current directory or one of its parent directories.
;; - Interactive Functions: Provides tools to check and navigate to loaded
;; settings.
;; - Selective Loading: Restricts loading to directories specified in
;; `local-config-allowed-directories'.
;; - Automatic Configuration Discovery: Searches for and loads
;; '.emacs-local-config.el' file from the directory of the current buffer or
;; its parent directories.
;; - Selective Directory Loading: Restricts the loading of configuration files
;; to directories listed in the variable `local-config-allowed-directories'
;; and `local-config-denied-directories', ensuring control over where
;; configuration files are sourced from.
;; - The `local-config-mode' mode: Automatically loads the
;; '.emacs-local-config.el' file whenever a file is opened, leveraging the
;; `find-file-hook' to ensure that local configurations are applied.

;;; Code:

Expand All @@ -47,7 +51,7 @@
:tag "Github"
"https://github.com/jamescherti/local-config.el"))

(defcustom local-config-file-names '(".local-config.el")
(defcustom local-config-file-names '(".emacs-local-config.el")
"List of filenames for local Emacs configuration files.
This list contains filenames that Emacs will search for in the directory
Expand All @@ -57,9 +61,10 @@ from the buffer's directory and moving upward through its parent directories.
Each entry in this list should be a string representing a filename. The
first existing file found in the hierarchy will be used for configuration.
For example, if the list contains the .local-config.el and .my-emacs-rc.el
files, Emacs will search for the .local-config.el file first, and if it is not
found, it will then search for the .my-emacs-rc.el file'."
For example, if the list contains the .emacs-local-config.el and
.project-config.el files, Emacs will search for the .emacs-local-config.el file
first, and if it is not found, it will then search for the .project-config.el
file'."
:type '(repeat string)
:group 'local-config)

Expand All @@ -69,12 +74,12 @@ found, it will then search for the .my-emacs-rc.el file'."
:group 'local-config)

(defcustom local-config-allowed-directories '()
"List of directory names where '.local-config.el' is allowed."
"List of directory names where local config files are allowed."
:type '(repeat directory)
:group 'local-config)

(defcustom local-config-denied-directories '()
"List of directory names where '.local-config.el' is denied."
"List of directory names where local config files are denied."
:type '(repeat directory)
:group 'local-config)

Expand All @@ -98,13 +103,13 @@ otherwise."
allowed-directories))

(defun local-config-get-dir ()
"Return the directory of the currently loaded `.local-config.el` file.
"Return the directory of the currently loaded local config file.
Return `nil` if the local Emacs RC 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.el` file.
"Return the file of the currently loaded local config file.
Return `nil` if the local Emacs RC file has not been loaded."
(when (bound-and-true-p local-config--file)
local-config--file))
Expand Down

0 comments on commit 1fd3c39

Please sign in to comment.