मुझे this question विषय पर कुछ हद तक मिला, लेकिन एक्सटेंशन पर आधारित मामूली मोड (या इसकी एक सूची) सेट करने के लिए [emacs] में कोई तरीका है? उदाहरण के लिए, यह पता लगाने के लिए कि प्रमुख मोड तोविस्तार पर आधारित 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))))
आप 'चौधरी वी ऑटो मोड-alist' को देखते हैं, आमतौर पर एक्सटेंशन के रूप में' लिखा जाता है "। \\ नोटों \\ ''' । अंतिम * एकल * उद्धरण देखें। –
मैं शापित हो जाऊंगा। याद किया कि जब मैं टाइप कर रहा था। शायद पीछे की पिछली बैकस्लैश चीज बताती है -_- –