From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: charles@aurox.ch (Charles A. Roelli) Newsgroups: gmane.emacs.help Subject: Re: automatically change input method based on context Date: Sat, 21 Jan 2017 20:19:33 +0100 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1485036861 728 195.159.176.226 (21 Jan 2017 22:14:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 21 Jan 2017 22:14:21 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 21 23:14:17 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 1cV3uz-0006N8-Md for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 23:13:53 +0100 Original-Received: from localhost ([::1]:33493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cV3v4-0006FA-Ih for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 17:13:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cV1DX-0003jU-Vn for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 14:20:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cV1DU-0003H7-RR for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 14:20:51 -0500 Original-Received: from [195.159.176.226] (port=37600 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cV1DU-0003GS-KG for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 14:20:48 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cV1Ct-0007g5-Qp for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 20:20:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 34 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:CUSLeJTa/oShSfH82SlxGhEt1zA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-Mailman-Approved-At: Sat, 21 Jan 2017 17:13:23 -0500 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:112139 Archived-At: Hi Stefan, Thanks for your help. Here's a full example should anyone be interested: (defun my-font-lock-comment-to-cursor-sensor (start end &rest _) (save-excursion (goto-char start) (while (< (point) end) (if (not (eq (get-text-property (point) 'face) 'font-lock-comment-face)) (goto-char (or (text-property-any (point) end 'face 'font-lock-comment-face) end)) (let ((s (point))) (goto-char (or (text-property-not-all (point) end 'face 'font-lock-comment-face) end)) (put-text-property s (point) 'cursor-sensor-functions '(motion-set-input-method))))))) (defun motion-set-input-method (_window _oldpos dir) (pcase dir ('entered (set-input-method "french-prefix")) ('left (set-input-method nil)))) (cursor-sensor-mode 1) (advice-add 'font-lock-fontify-syntactically-region :after #'my-font-lock-comment-to-cursor-sensor) Cheers, Charles