Function: generic-mode-find-file-hook

generic-mode-find-file-hook is a byte-compiled function defined in generic-x.el.gz.

Signature

(generic-mode-find-file-hook)

Documentation

Hook function to enter Default-Generic mode automatically.

Done if the first few lines of a file in Fundamental mode start with a match for the regexp in generic-find-file-regexp, unless the file's name matches the regexp which is the value of the variable generic-ignore-files-regexp.

This hook will be installed if the variable generic-use-find-file-hook is non-nil. The variable generic-lines-to-scan determines the number of lines to look at.

Source Code

;; Defined in /usr/src/emacs/lisp/generic-x.el.gz
;; A more general solution would allow us to enter generic-mode for
;; *any* comment character, but would require us to synthesize a new
;; generic-mode on the fly. I think this gives us most of what we
;; want.
(defun generic-mode-find-file-hook ()
  "Hook function to enter Default-Generic mode automatically.

Done if the first few lines of a file in Fundamental mode start
with a match for the regexp in `generic-find-file-regexp', unless
the file's name matches the regexp which is the value of the
variable `generic-ignore-files-regexp'.

This hook will be installed if the variable
`generic-use-find-file-hook' is non-nil.  The variable
`generic-lines-to-scan' determines the number of lines to look at."
  (when (and (eq major-mode 'fundamental-mode)
	     (or (null generic-ignore-files-regexp)
		 (not (string-match-p
		       generic-ignore-files-regexp
		       (file-name-sans-versions buffer-file-name)))))
    (save-excursion
      (goto-char (point-min))
      (when (re-search-forward generic-find-file-regexp
			       (save-excursion
				 (forward-line generic-lines-to-scan)
				 (point)) t)
	(goto-char (point-min))
	(default-generic-mode)))))