인 이맥스 자동 마이너 모드 this question이 다소 있는데, 확장자을 기반으로 마이너 모드 (또는 그 목록)를 설정하는 [emacs의] 방법이 있습니까? 예를 들어, 주요 모드가 너무확장자가
(setq auto-mode-alist
(cons '("\\.notes$" . text-mode)
auto-mode-alist))
처럼 조작과 제가 이상적으로 할 수 있도록하고 싶습니다 것은 링크의
(setq auto-minor-mode-alist
(cons '("\\.notes$" . auto-fill-mode)
auto-minor-mode-alist))
수락 대답 할 수 있다는 것을 알아 꽤 쉽게 질문에 후크가 포함되어 있습니다 (구체적으로 temp-buffer-setup-hook
). 이것을 사용하려면 같은 후크에 기능을 추가 할 필요가 있으므로
(add-hook 'temp-buffer-setup-hook 'my-func-to-set-minor-mode)
내 질문은 두 가지 :
- 이 작업을 수행하는 쉬운 방법이 있나요, 주요 모드와 유사?
- 그렇지 않은 경우 어떻게 훅에 대한 함수를 작성합니까?
- 정규식과 파일 경로를 비교해야합니다.
- 일치하는 경우 원하는 모드를 활성화하십시오 (예 :
auto-fill-mode
). 솔루션에서
희미한 및 버그 시도 :
(defvar auto-minor-mode-alist()
"Alist of filename patterns vs correpsonding minor mode functions, see `auto-mode-alist'
All elements of this alist are checked, meaning you can enable multiple minor modes for the same regexp.")
(defun enable-minor-mode-based-on-extension()
"check file name against auto-minor-mode-alist to enable minor modes
the checking happens for all pairs in auto-minor-mode-alist"
(when buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name))
(alist auto-minor-mode-alist))
;; 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-p (regexp-quote remote-id) name))
(setq name (substring name (match-end 0))))
(while (and alist (caar alist) (cdar alist))
(if (string-match (caar alist) name)
(funcall (cdar alist) 1))
(setq alist (cdr alist))))))
(add-hook 'find-file-hook 'enable-minor-mode-based-on-extension)
참고 :
; Enables the given minor mode for the current buffer it it matches regex
; my-pair is a cons cell (regular-expression . minor-mode)
(defun enable-minor-mode (my-pair)
(if (buffer-file-name) ; If we are visiting a file,
; and the filename matches our regular expression,
(if (string-match (car my-pair) buffer-file-name)
(funcall (cdr my-pair))))) ; enable the minor mode
; used as
(add-hook 'temp-buffer-setup-hook
(lambda() (enable-minor-mode ("\\.notes$" . auto-fill-mode))))
이 확장은 보통'으로 작성됩니다. "\\ 메모를 \\'"' . 최종 * 싱글 * 견적을 참조하십시오. –
나는 지옥에 빠질 것이다. 내가 그 타입을 할 때 그것을 놓쳤다. 아마도 후행 백 슬래시 문제를 정확히 설명 할 것입니다. -_- –