How to use the same file extension for different major modes

I am using a custom version org-mode

called lawlist-org-mode

- every function and variable is prefixed lawlist-

and the modified version has a lot of custom functionality that is not available in the stock version. Sometimes I like to use a stock version org-mode

, but that requires a manual change auto-mode-alist

and then restarting Emacs. This is necessary because of the function and variable org-agenda-files

and validation, which org-mode

performs validation of the main major mode. Is there an efficient way to modify this programmatically depending on the function being called?

The stock org-mode

needs this entry:

(add-to-list 'auto-mode-alist '("\\.todo\\'" . org-mode))

      

The custom version called lawlist-org-mode

needs this entry:

(add-to-list 'auto-mode-alist '("\\.todo\\'" . lawlist-org-mode))

      

<strong> Examples:

  • If I call M-x org-agenda

    , the files .todo

    should be in org-mode

    .

  • If I call M-x lawlist-org-agenda

    , the file .todo

    should be in lawlist-org-mode

    .


Some ideas . org-agenda-files

are usually accessed by org-agenda functions using the following lines of code - (org-agenda-files nil 'ifmode) . . . (while (setq file (pop files))

. Perhaps modifying the function org-agenda-files

would be an option?

+3


source to share


1 answer


The FUNCTION

element part auto-mode-alist

(i.e. cdr) is just a function. It is called, in principle, to create the main mode. But he can do anything.

In particular, you can have an entry ("\\.todo\\'" . foo)

where the function foo

conditionally calls either lawlist-org-mode

or org-mode

.



For example, it can be used lawlist-org-mode

when the moon is full and org-mode

otherwise. Or it can check the global variable that you are setting when you want to switch from one to the other. Etc.

At least my auto-mode-alist

doc line reading . I have never tried it.

+5


source







All Articles