Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tarao/multi-mode-util

A package of Emacs Lisp for easy-to-use multiple major mode.
https://github.com/tarao/multi-mode-util

emacs emacs-lisp

Last synced: 12 days ago
JSON representation

A package of Emacs Lisp for easy-to-use multiple major mode.

Awesome Lists containing this project

README

        

= multi-mode-util

== Usage

Locate multi-mode-util.el, multi-mode+viper.el and
multi-mode+evil.el somewhere in your load path.

Write the following line in your .emacs.

(require 'multi-mode-util)

Then you will be able to use functions listed bellow.
- multi-mode-init
- multi-mode-quit
- multi-install-chunk-finder
- multi-run-in-base-buffer

This package fixes the following problems in the original multi-mode.
- Undo/redo-ing is inconsistent in multiple modes.
- Activating mark (especially with transient-mark-mode) across the boundary between multiple modes does not work.
- States of viper-mode get inconsistent in multiple modes.
- States of evil-mode get inconsistent in multiple modes.
- Fontification by font-lock-mode does not work properly.
- A lock file is produced even if the file is not modified. (See {issue #1}[https://github.com/tarao/multi-mode-util/issues/1])

== Requirement

multi-mode.el:: http://www.loveshack.ukfsn.org/emacs/multi-mode.el

== Example 1

If you are editing HTML file with embedded Python code between
\ and ?>, then using the following settings
provides you html-mode in HTML code and python-mode
in Python code.

(require 'multi-mode-util)
(defun pytml-mode ()
"Treat the current buffer as a pytml buffer."
(interactive)
(html-mode)
(multi-install-chunk-finder
"<\\?python[\r\n\t ]" "[\r\n\t ]\\?>" 'python-mode))
(setq auto-mode-alist (cons '("\\.pytml$" . pytml-mode) auto-mode-alist))

== Example 2

hatena-diary-super-pre-notation in the following code enables
specific major mode for certain programming language in the text
between >|language| and ||\<. text-mode
specified to multi-mode-init is used for the rest of the text
in the buffer.

(require 'multi-mode-util)
(setq hatena-diary-super-pre-languages '(java javascript lisp ruby))
(defun hatena-diary-super-pre-notation ()
(interactive)
(multi-mode-init 'text-mode)
(dolist (l hatena-diary-super-pre-languages)
(let ((str (symbol-name l)))
(multi-install-chunk-finder (concat "^>|" str "|$") "^||<$"
(intern (concat str "-mode"))))))

== Functions

=== multi-mode-init (&optional BASE-MODE)

This function sets the base major mode BASE-MODE for the
buffer. It is equivalent to (multi-install-mode BASE-MODE nil
t)
and this is implicitly done by the first call of
multi-install-mode for a non-base major mode. So, (unlike in
the older versions) you don't need to call this function explicitly.

=== multi-mode-quit ()

Quit multi-mode. All indirect buffers for non-base major
modes are killed.

=== multi-install-chunk-finder (START-PAT END-PAT MODE)

This function installs a non-base major mode MODE. The major
mode will be activated in portions of buffer between strings matching
with START-PAT and END-PAT regular expressions.

=== multi-run-in-base-buffer (FUNC &optional TRACK-POSITION)

This function advises a function specified by symbol FUNC
being called in the base major mode. Unless TRACK-POSITION
is t, the cursor position will be restored after the function
call.