unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Tom Tromey <tom@tromey.com>, Emacs discussions <emacs-devel@gnu.org>
Subject: Re: exposing the effective mode in a multi-mode
Date: Mon, 18 Sep 2017 12:01:09 +0300	[thread overview]
Message-ID: <7db25c04-9899-605a-e349-016b2a78d92e@yandex.ru> (raw)
In-Reply-To: <874ls0c40s.fsf@tromey.com>

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?



  reply	other threads:[~2017-09-18  9:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-17 23:13 exposing the effective mode in a multi-mode Tom Tromey
2017-09-18  9:01 ` Dmitry Gutov [this message]
2017-09-20  4:18   ` Tom Tromey
2017-09-21 14:19     ` Dmitry Gutov
2017-09-18  9:30 ` Alan Mackenzie
2017-09-20  4:21   ` Tom Tromey
2017-09-19 12:23 ` Stefan Monnier
2017-10-08 21:20   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7db25c04-9899-605a-e349-016b2a78d92e@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).