|
From: | Dmitry Gutov |
Subject: | Re: exposing the effective mode in a multi-mode |
Date: | Mon, 18 Sep 2017 12:01:09 +0300 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Thunderbird/56.0 |
On 9/18/17 2:13 AM, Tom Tromey wrote:
I noticed that company couldn't do CSS completion in a <style> element in mhtml-mode. company-css understands how web-mode handles sub-modes, by calling a web-mode function ("web-mode-language-at-pos") directly, but it doesn't understand mhtml-mode. So, I'd like to propose this patch for Emacs 26. It adds a new function to prog-mode.el so that multi-modes can expose the sub-mode at point. It also changes mhtml-mode to set the new variable to make this work.
Looks good to me, but consider this: sometimes (not too often, though) we have several major modes corresponding to a language. and they don't inherit from one another. Example: perl-mode and cperl-mode.
So I thought it might be useful to return the name of the language instead of the mode. The default implementation could look like this:
(defun prog-effective-lang () (intern (replace-regexp-in-string "-mode\\'" "" (symbol-name major-mode))))The "extra" major modes would have to provide their own implementations, though. Although define-derived-mode could grow a new keyword parameter, to make this easier.
+(defvar-local prog-effective-mode-function nil + "When non-nil, provides the effective mode at point for embedded code chunks. +When non-nil, this is a function that will be called by +`prog-effective-mode' to find the effective major mode at point. +This function should return a symbol naming a major mode, e.g. `css-mode'. +It may return nil to mean the \"outer\" major mode.") + +(defun prog-effective-mode () + "When non-nil, returns the effective mode at point.
Can it return nil? When?
[Prev in Thread] | Current Thread | [Next in Thread] |