There are a number of ways to identify the major mode for a file that don't rely on an extension, see Choosing File Modes in the manual.
Depending on the kinds of files you are dealing with, perhaps you could use the magic-mode-alist
. Also note that auto-mode-alist
is not limited to matching extensions: you can match any part of the file name or path.
If the files you are dealing with are not consistent enough for those mechanisms, one option is to add auto-mode-alist
entries that match the entire file name, or match the root path of some project and call a custom function to match names to modes.
If all the files in a given directory are of the same type you could also use a directory-local variable to set the mode. Directory variables can be set in your init file rather than in a .dir-locals file -- see Directory Variables for details.
Update
Here's a quick attempt at managing your own alist of absolute file names and major-modes.
(defvar my-custom-mode-alist '())
(defvar my-custom-mode-alist-file (expand-file-name "custom-file-assoc" user-emacs-directory))
;; command to save the file->mode association of the current buffer
(defun save-file-mode-association ()
(interactive)
(when buffer-file-name
(add-to-list 'my-custom-mode-alist (cons buffer-file-name major-mode))
(write-custom-mode-alist my-custom-mode-alist-file)))
(defun write-custom-mode-alist (file)
(with-current-buffer (get-buffer-create " *Custom File Assocations*")
(goto-char (point-min))
(delete-region (point-min) (point-max))
(pp my-custom-mode-alist (current-buffer))
(condition-case nil
(write-region (point-min) (point-max) file)
(file-error (message "Can't write %s" file)))
(kill-buffer (current-buffer))
(message "Wrote custom file associations to file %s" file)))
(defun load-custom-mode-alist (file)
(when (file-exists-p file)
(with-current-buffer
(let ((enable-local-variables nil))
(find-file-noselect file))
(goto-char (point-min))
(setq my-custom-mode-alist (read (current-buffer)))
(setq auto-mode-alist (append auto-mode-alist my-custom-mode-alist))
(kill-buffer (current-buffer)))))
;; Load any custom file associations and add them to auto-mode-alist
(load-custom-mode-alist my-custom-mode-alist-file)