Created
July 23, 2026 01:32
-
-
Save codemartial/41b499514f3568e9b4158b962acac003 to your computer and use it in GitHub Desktop.
Emacs command to open a file and its side car side-by-side
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun find-sidecar (file extension) | |
| "Open FILE and its EXTENSION sidecar in adjacent windows. | |
| Prefer an existing window to the left, then one to the right." | |
| ;; Usage: | |
| ;; M-x find-sidecar RET | |
| ;; File: path/to/file.ext RET | |
| ;; Sidecar extension: ext2 RET | |
| ;; | |
| ;; Opens: | |
| ;; path/to/file.ext | |
| ;; path/to/file.ext2 | |
| ;; | |
| ;; The extension should not include the leading dot. | |
| (interactive "fFile: \nsSidecar extension: ") | |
| (let* ((active (selected-window)) | |
| (left (window-in-direction 'left active)) | |
| (file-window (or left active)) | |
| (sidecar-window | |
| (if left | |
| active | |
| (or (window-in-direction 'right active) | |
| (split-window-right))))) | |
| (set-window-buffer file-window | |
| (find-file-noselect file)) | |
| (set-window-buffer sidecar-window | |
| (find-file-noselect | |
| (file-name-with-extension file extension))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment