From: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
To: 60980@debbugs.gnu.org
Cc: Juri Linkov <juri@linkov.net>
Subject: bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map
Date: Sat, 21 Jan 2023 14:07:31 +0530 [thread overview]
Message-ID: <TY2PR0101MB369376FB701F22BBA319C290DACA9@TY2PR0101MB3693.apcprd01.prod.exchangelabs.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1813 bytes --]
FR: It would be useful to have a repeat-exit-function for a repeat-map
Overview of `thing.el`
==============
The attached file `thing.el`
- allows navigation by "thing"
- highlights the thing that is being navigated
- you can switch to a "parent thing" while navigating a "thing"
Video Demo of `thing.el`
===============
See the video https://github.com/rnchzn/scratch/issues/1 as I test drive `thing.el`.
The right window shows the `*lossage*` buffer, and it updates as I run commands.
What happens in the Video
=================
In the context of the above video, I start navigating the `symbol` thing, and switch to the `sexp / list` thing (`sexp / list` is the parent of `symbol` thing)
Additional details on `thing.el`
===================
I am using s-i, s-j, s-k and s-l as <up>, <left>, <down> and <right> keys using `input-decode-map`.
There are four keymaps.
- s-l and s-j are prefix keys that invoke `forward-thing-map` and `backward-thing-map`.
- The `thing-symbol-map` has `symbol` commands.
- The `thing-sexp-map` has `sexp` commands.
When `thing-symbol-map` is active you can press <up> or s-i to move to `thing-sexp-map`.
What I need from repeat.el
================
When I exit the repeat map---for example when I press <return> in the video, and leave the "navigation mode" to "edit mode"---I want to unhighight the thing.
That is I propose that there be a provision in `repeat.el` to associate an `exit-function` with a repeatable map
(put 'thing-sexp-map 'repeat-exit-function 'thing-unhighlight)
Additional Note
==========
If you squint a bit, `repeat-echo-function` is an `exit-function` ... but the problem is it doesn't provide what map is being exited.
See bug#60353: 30.0.50; Make `repeat-echo-function` as a LIST of functions
[-- Attachment #2: thing.el --]
[-- Type: text/x-emacs-lisp, Size: 3176 bytes --]
(defface thing-face
'((t :background "light gray"))
"Face for hi-lock mode." :group 'hi-lock-faces)
(defvar thing)
(put 'thing 'thing t)
(put 'thing 'face 'thing-face)
(defvar-local thing-overlay nil)
(defun thing-highlight
(obj)
(let*
((bounds
(bounds-of-thing-at-point obj))
ov)
(cond
(thing-overlay
(move-overlay thing-overlay
(car bounds)
(cdr bounds)))
(obj
(setq ov
(make-overlay
(car bounds)
(cdr bounds)))
(overlay-put ov 'category 'thing)
(setq thing-overlay ov)))))
(defun thing-unhighlight nil
(interactive)
(when thing-overlay
(delete-overlay thing-overlay)))
;;; thing-funs
(defun symbol-thing-forward nil
(interactive)
(call-interactively 'forward-symbol)
(thing-highlight 'symbol))
(defun symbol-thing-backward nil
(interactive)
(call-interactively 'backward-symbol)
(thing-highlight 'symbol))
(defun sexp-thing-forward nil
(interactive)
(call-interactively 'forward-sexp)
(thing-highlight 'sexp))
(defun sexp-thing-backward nil
(interactive)
(call-interactively 'backward-sexp)
(thing-highlight 'sexp))
(defun sexp-thing-up nil
(interactive)
(call-interactively 'backward-up-list)
(thing-highlight 'sexp))
(defun sexp-thing-down nil
(interactive)
(call-interactively 'down-list)
(thing-highlight 'sexp))
;;; definitions
(require 'thingatpt)
(define-key input-decode-map
(kbd "s-l")
(kbd "<right>"))
(defvar-keymap forward-thing-map "." 'symbol-thing-forward "x" 'sexp-thing-forward)
(global-set-key
(kbd "<right>")
forward-thing-map)
(define-key input-decode-map
(kbd "s-j")
(kbd "<left>"))
(defvar-keymap backward-thing-map "." 'symbol-thing-backward "x" 'sexp-thing-backward)
(global-set-key
(kbd "<left>")
backward-thing-map)
(defvar-keymap thing-symbol-map :repeat
(:enter
(symbol-thing-forward symbol-thing-backward forward-symbol backward-symbol)
:exit
(sexp-thing-up))
"]" 'symbol-thing-forward "<right>" 'symbol-thing-forward "[" 'symbol-thing-backward "<left>" 'symbol-thing-backward "<up>" 'sexp-thing-up)
(dolist
(fn
'(symbol-thing-forward symbol-thing-backward forward-symbol backward-symbol sexp-thing-up))
(put fn 'repeat-check-key 'no))
(put 'thing-symbol-map 'repeat-exit-function 'thing-unhighlight)
(defvar-keymap thing-sexp-map :repeat
(:enter
(sexp-thing-forward sexp-thing-backward sexp-thing-up sexp-thing-down forward-sexp backward-sexp backward-up-list down-list)
:exit nil)
"]" 'sexp-thing-forward "<right>" 'sexp-thing-forward "[" 'sexp-thing-backward "<left>" 'sexp-thing-backward "<up>" 'sexp-thing-up "<down>" 'sexp-thing-down)
(dolist
(fn
'(sexp-thing-forward sexp-thing-backward sexp-thing-up sexp-thing-down forward-sexp backward-sexp backward-up-list down-list))
(put fn 'repeat-check-key 'no))
(put 'thing-sexp-map 'repeat-exit-function 'thing-unhighlight)
(defun thing-backward
(which-thing)
(interactive)
(forward-thing which-thing -1))
(defun backward-symbol nil
(interactive)
(thing-backward 'symbol))
(repeat-mode -1)
(repeat-mode 1)
(provide 'thing)
next reply other threads:[~2023-01-21 8:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-21 8:37 Ramesh Nedunchezian [this message]
[not found] ` <handler.60980.B.167429057211919.ack@debbugs.gnu.org>
2023-01-21 8:46 ` bug#60980: Acknowledgement (FR: It would be useful to have a repeat-exit-function for a repeat-map) Ramesh Nedunchezian
2023-01-30 8:29 ` bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map Juri Linkov
2023-02-12 4:58 ` Ramesh Nedunchezian
2023-02-12 17:23 ` Juri Linkov
2023-02-13 17:47 ` Juri Linkov
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=TY2PR0101MB369376FB701F22BBA319C290DACA9@TY2PR0101MB3693.apcprd01.prod.exchangelabs.com \
--to=rameshnedunchezian@outlook.com \
--cc=60980@debbugs.gnu.org \
--cc=juri@linkov.net \
/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).