Function: set-auto-mode--apply-alist

set-auto-mode--apply-alist is a byte-compiled function defined in files.el.gz.

Signature

(set-auto-mode--apply-alist ALIST KEEP-MODE-IF-SAME DIR-LOCAL)

Documentation

Helper function for set-auto-mode.

This function takes an alist of the same form as auto-mode-alist. It then tries to find the appropriate match in the alist for the current buffer; setting the mode if possible. Return non-nil if the mode was set, nil otherwise. DIR-LOCAL non-nil means this call is via directory-locals, and extra checks should be done.

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun set-auto-mode--apply-alist (alist keep-mode-if-same dir-local)
  "Helper function for `set-auto-mode'.
This function takes an alist of the same form as
`auto-mode-alist'.  It then tries to find the appropriate match
in the alist for the current buffer; setting the mode if
possible.
Return non-nil if the mode was set, nil otherwise.
DIR-LOCAL non-nil means this call is via directory-locals, and
extra checks should be done."
  (if buffer-file-name
      (let (mode
            (name buffer-file-name)
            (remote-id (file-remote-p buffer-file-name))
            (case-insensitive-p (file-name-case-insensitive-p
                                 buffer-file-name)))
        ;; 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))))
        (setq mode (set-auto-mode--find-matching-alist-entry
                    alist name case-insensitive-p))
        (when (and dir-local mode
                   (not (set-auto-mode--dir-local-valid-p mode)))
          (message "Ignoring invalid mode `%S'" mode)
          (setq mode nil))
        (when mode
          (set-auto-mode-0 mode keep-mode-if-same)
          t))))