From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Michael Anckaert Newsgroups: gmane.emacs.help Subject: Re: Enabling mode for part of buffer / region Date: Thu, 23 Jan 2020 20:33:54 +0100 Message-ID: <87y2tyx90d.fsf@winston.localdomain> References: <87tv4mv5rg.fsf@winston.localdomain> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="43639"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.1.0; emacs 26.3 Cc: Michael Anckaert , Help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 23 20:53:05 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iuiXI-000BIA-7d for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jan 2020 20:53:04 +0100 Original-Received: from localhost ([::1]:60758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuiXH-0000Ce-8j for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jan 2020 14:53:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38044) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuiTF-00018H-QY for Help-gnu-emacs@gnu.org; Thu, 23 Jan 2020 14:48:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuiEo-0002yo-IH for Help-gnu-emacs@gnu.org; Thu, 23 Jan 2020 14:33:59 -0500 Original-Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:36286) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iuiEo-0002xI-BN for Help-gnu-emacs@gnu.org; Thu, 23 Jan 2020 14:33:58 -0500 Original-Received: by mail-wm1-x334.google.com with SMTP id p17so3761575wma.1 for ; Thu, 23 Jan 2020 11:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sinax.be; s=google; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=SvFIQfdBROdVn3O7JAV9FJEH66w4VmS2vKjATt9s1VQ=; b=DARxAR4FxIHVmIgbmNejFQ5g61GgarkrIQ18sREEoTcgdjvYeUS2YUL/PTHN/1hZte jVAS/wfnGnOVKTazlAS11Py1NBehvqxbq7ZZi5k+hTCoYNqm9SqUrT4cTGiAT0jP+C8J udmuA2Rv1kh6QRbSuNDCz/ay1/DywX+Lvt8HY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=SvFIQfdBROdVn3O7JAV9FJEH66w4VmS2vKjATt9s1VQ=; b=Mb5LqhBH8TVGUYVG7pLb6kMdLvF2XR9f2cS6UhBYpyhFDBKjenGEDsoPiPZkUG14E0 byR62YxuBnGF9uoyrOaRMxemPvvBddZWXEGtGD166AUSYG5kot2t/Y1OiRvk17bmMY/C bSnFMfc49M+BWGYdi434/qRj7V/+mAwOaTTupt2dpYhJueUj9wVLo2JW+p3it+ynJZ5F iClEM6XxLGK0ITGwnrxlbTRQTOlkoXtNMsgLkb8ytMiKeLEyjXKIXlWJ94JxUG4MT7kE k0TnWsG1i2TQxOMynhifrM7i+bboJcyjrgLg7Y7aaCxZeDLf3/pVAZLUXApixT8SycB5 c+ig== X-Gm-Message-State: APjAAAV2NaDde4u1ExpWDZ7xlo7myN+5DRyzwtaiMSoidN9a/GNGKONm O1z/wycjyuIh72UiNRHU7hqr3HIRm4yNWAgA X-Google-Smtp-Source: APXvYqzCDmnexp+ZyDWWGb+qrHLhSwkghwUt6rMYsVxZ9CANwgA+9yN6DD7whwgSXGVTULFmHrQS5w== X-Received: by 2002:a05:600c:2117:: with SMTP id u23mr5914839wml.106.1579808036157; Thu, 23 Jan 2020 11:33:56 -0800 (PST) Original-Received: from winston.localdomain (ptr-dkbjq8c4ccvg9pmku4z.18120a2.ip6.access.telenet.be. [2a02:1811:c412:9000:fa3c:f21b:fa47:3f93]) by smtp.gmail.com with ESMTPSA id y7sm9990196wmd.1.2020.01.23.11.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 11:33:55 -0800 (PST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::334 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:122271 Archived-At: 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