Emacs: open all .txt files in a specific directory in a specific native mode

EDIT: It turns out that the second edit in my .emacs file really works. (See comments below this entry.)

I tried a couple of .emacs add-ons so that all txt files opened in emacs use orgmode. They did not work. How can i do this?

;;SET EMACS AS DEFAULT MAJOR MODE TO FOR ALL FILES WITH AN UNSPECIFIED MODE
(setq default-major-mode 'org-mode)

;;OPEN ALL TXT FILES IN ORGMODE
(add-to-list 'auto-mode-alist '("\\.txt$" . org-mode))

Additionally:

It would be even better to open only txt files in a specific orgmode directory. Any hint on how this could be done could also be appreciated.

+5
source share
4 answers

You can implement a hook that checks the file directory and changes the buffer mode:

(add-hook 'find-file-hooks 
          (lambda ()
            (let ((file (buffer-file-name)))
              (when (and file (equal (file-name-directory file) "c:/temp/"))
                (org-mode)))))

. emacs .

; -*- mode: org;-*-
* header 1
** header 2
+2

- . , , , , .

.dir-locals.el .

:

((nil (eval . (if (string-match ".txt$" (buffer-file-name))(org-mode)))))

: (nil), eval :

(if ....  (org-mode))
+4

auto-mode-alist - , "^/path/to/.*\\.txt$"

+3

, , , yibe elisp - Emacs -

(defun use-org-mode-for-dot-txt-files-in-owncloud ()
  (when (and (string-match owncloud buffer-file-name)
             (string-match "\\.txt\\'" buffer-file-name))
    (org-mode)))
(add-hook 'find-file-hook 'use-org-mode-for-dot-txt-files-in-owncloud)

Thus, although my own web and mobile phone applications are currently only .txtfile friendly , I can use the Org mode for Emacs from my PC.

(If I installed all the files .txtto use Org-mode, it breaks todotxt-mode.)

(Note that owncloudthis is a string variable equal to my ownCloud path.)

0
source

All Articles