From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: phillip.lord@russet.org.uk (Phillip Lord) Newsgroups: gmane.emacs.help Subject: Re: automatically change input method based on context Date: Sat, 21 Jan 2017 23:34:03 +0000 Message-ID: <87h94s56ok.fsf@russet.org.uk> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1485041725 22050 195.159.176.226 (21 Jan 2017 23:35:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 21 Jan 2017 23:35:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: charles@aurox.ch (Charles A. Roelli) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 22 00:35:21 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cV5BP-00038J-UR for geh-help-gnu-emacs@m.gmane.org; Sun, 22 Jan 2017 00:34:56 +0100 Original-Received: from localhost ([::1]:33683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cV5BT-00050J-8D for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 18:34:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cV5Ar-000502-1J for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 18:34:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cV5Am-00057a-5L for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 18:34:21 -0500 Original-Received: from mailgw.mycpanelcloud.co.uk ([185.116.214.213]:50202) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cV5Al-00056g-MR for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 18:34:16 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mailgw.mycpanelcloud.co.uk (Postfix) with ESMTP id 6AC37C6466 for ; Sat, 21 Jan 2017 23:33:49 +0000 (GMT) X-Virus-Scanned: by SpamTitan at mycpanelcloud.co.uk Original-Received: from mailgw.mycpanelcloud.co.uk (localhost [127.0.0.1]) by mailgw.mycpanelcloud.co.uk (Postfix) with ESMTP id 819D9C63D6 for ; Sat, 21 Jan 2017 23:33:48 +0000 (GMT) Original-Received: from cloud103.planethippo.com (cloud103.planethippo.com [31.216.48.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailgw.mycpanelcloud.co.uk (Postfix) with ESMTPS id 73D2FC623E for ; Sat, 21 Jan 2017 23:33:48 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=russet.org.uk; s=default; h=Content-Type:MIME-Version:References:Message-ID :Date:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/PHSOd4yYKSa9JSmgciL20LieABPX/Q9PaJpDRtbYcM=; b=YrHa/NL6SqMW0DbGmlRjxRjSk 5CaoMfAoBdmpO9E5cQPEV7GcfkfHMp6vg96ssu82WlM4Wx8LsgcAU0p6aPTJ4mp56RPK4Dn5wxYOJ WvjOQc5eYBnwRLen7Vvv33RBqqCkNX3OfDFXZ0VR8NLA41FFRJrKhxTvkFDCSruKnro3wFt/va9Rx 4VSORXuZno+3TJvbWZqQTaffxNdIAlIAVuACotGcI9C0L+mTRZO8sOliPQ5ws7oje3HuxagmdaFRN xpSOUrgkmgWa1zwoMvsZJVgTQEmHuas+3F9qwH2+Vm2L+vDa1c5IbdlqchXr6FcNYrSJNT+tl+KE+ VzOZkTkmQ==; Original-Received: from host-78-147-211-224.as13285.net ([78.147.211.224]:38642 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from ) id 1cV5Ag-002krU-Sb; Sat, 21 Jan 2017 23:34:11 +0000 In-Reply-To: (Charles A. Roelli's message of "Thu, 19 Jan 2017 12:02:57 +0100") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud103.planethippo.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - russet.org.uk X-Get-Message-Sender-Via: cloud103.planethippo.com: authenticated_id: phillip.lord@russet.org.uk X-Authenticated-Sender: cloud103.planethippo.com: phillip.lord@russet.org.uk X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x [fuzzy] X-Received-From: 185.116.214.213 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112140 Archived-At: You might want to take a look at my package: https://github.com/phillord/tmmofl It does pretty what you want -- it runs a function when point enters into text with a particular highlighting, and another when you move out. I use it to turn auto-fill-mode on in comments and off everywhere else. It uses post-command-hook to do it's stuff. Let me know how you get on! charles@aurox.ch (Charles A. Roelli) writes: > Hi, > > I'd like Emacs to switch input method automatically based on the > font-lock face property of point. As an example, if point is in a > comment, Emacs should run `(set-input-method "french-prefix")', and then > when point leaves the comment, `(set-input-method nil)' should run > again. I managed to do it with a timer (not really elegant), but it > seems like this is something that would be possible with > `cursor-sensor-mode'. > > My idea is to: > 1. Add a `cursor-sensor-functions' property to all the text that is > fontified as a comment (and somehow keep this dynamically updated). > 2. Use this function in `cursor-sensor-functions' to handle changing the > input method: > > (defun motion-set-input-method (window oldpos dir) > (pcase dir > ('entered (set-input-method "french-prefix")) > ('left (set-input-method nil)))) > > But I don't know how to go about (1). Any advice? > > Cheers, > Charles