From: Michael Anckaert <michael.anckaert@sinax.be>
To: Drew Adams <drew.adams@oracle.com>
Cc: Michael Anckaert <michael.anckaert@sinax.be>, Help-gnu-emacs@gnu.org
Subject: Re: Enabling mode for part of buffer / region
Date: Thu, 23 Jan 2020 20:33:54 +0100 [thread overview]
Message-ID: <87y2tyx90d.fsf@winston.localdomain> (raw)
In-Reply-To: <b655d034-8e4d-4398-8965-ed953a4f124e@default>
Hey Drew, thanks for your reply. Your comment actually got me in the
right direction and I think I found a solution. Maybe not perfect
yet...
To answer your question on what I want to accomplish: Let's say I'm
writing an email and want to include some Python code. It would be
really useful to mark a part of the buffer as 'contains python code',
when I enter here I want to enable python-mode when editing.
The 4 lines below contain a small Python snippet that I would like to
edit using some features of python-mode. Thanks to your answer I found
a partial solution that enables me to narrow the buffer to that point,
enable python-mode and edit the code. When I widen I can return to
text-mode.
def greet(name: str):
print(f'Hello, {name}')
greet('Drew')
This solution is almost perfect but manually switching the modes back
and forth is somewhat of a hassle. While composing this email for
example I switched back from python-mode to text-mode, while I actually
needed to switch back to mu4e-compose-mode.
I'm looking for something like the code blocks inside an org-mode
document [0]. Just for fun I'm trying to whip up an elisp function that
will store the current mode before narrowing and restore the mode after
widening. But maybe there is a better way to achieve what I want to do.
[0] https://orgmode.org/manual/Structure-of-code-blocks.html
Drew Adams writes:
>> Suppose I'm writing an email and would like to enable python-mode in
>> the email, but only for a selected part.
>> Is this possible in Emacs?
>
> Please clarify just what you want to do.
>
> If you are using Lisp code you can use
> `save-restriction', narrow to the buffer portion
> of interest, change the mode, etc. Perhaps that
> is sufficient? What is it that you really want
> to do?
--
Michael Anckaert
+32 474 066 467
https://www.sinax.be
next prev parent reply other threads:[~2020-01-23 19:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 10:14 Enabling mode for part of buffer / region Michael Anckaert
2020-01-23 17:00 ` Drew Adams
2020-01-23 19:33 ` Michael Anckaert [this message]
2020-01-23 19:38 ` Drew Adams
2020-01-24 10:49 ` Michael Anckaert
2020-01-24 11:16 ` tomas
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y2tyx90d.fsf@winston.localdomain \
--to=michael.anckaert@sinax.be \
--cc=Help-gnu-emacs@gnu.org \
--cc=drew.adams@oracle.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.