Function: hyrolo-major-mode-from-file-name

hyrolo-major-mode-from-file-name is a byte-compiled function defined in hyrolo.el.

Signature

(hyrolo-major-mode-from-file-name NAME)

Documentation

Return major-mode function for file NAME from file name alone.

If no matching rule in hyrolo-auto-mode-alist or auto-mode-alist or NAME is invalid, return nil.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hyrolo.el
;; Adapted from `set-auto-mode' in "files.el" but greatly simplified.
(defun hyrolo-major-mode-from-file-name (name)
  "Return `major-mode' function for file NAME from file name alone.
If no matching rule in `hyrolo-auto-mode-alist' or `auto-mode-alist'
or NAME is invalid, return nil."
  (when (stringp name)
    (let ((remote-id (file-remote-p name))
	  (case-insensitive-p (file-name-case-insensitive-p
			       name))
	  mode)
      ;; Remove backup-suffixes from file name.
      (setq name (file-name-sans-versions name))
      ;; Remove remote file name identification.
      (when (and (stringp remote-id)
		 (string-match (regexp-quote remote-id) name))
	(setq name (substring name (match-end 0))))
      (let ((auto-mode-alist (append hyrolo-auto-mode-alist auto-mode-alist)))
	(while name
	  ;; Find first matching alist entry.
	  (setq mode
		(if case-insensitive-p
		    ;; Filesystem is case-insensitive.
		    (let ((case-fold-search t))
		      (assoc-default name auto-mode-alist
				     'string-match))
		  ;; Filesystem is case-sensitive.
		  (or
		   ;; First match case-sensitively.
		   (let ((case-fold-search nil))
		     (assoc-default name auto-mode-alist
				    'string-match))
		   ;; Fallback to case-insensitive match.
		   (and auto-mode-case-fold
			(let ((case-fold-search t))
			  (assoc-default name auto-mode-alist
					 'string-match))))))
	  (if (and mode
		   (consp mode)
		   (cadr mode))
	      (setq mode (car mode)
		    name (substring name 0 (match-beginning 0)))
	    (setq name nil))))
      mode)))