unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map
@ 2023-01-21  8:37 Ramesh Nedunchezian
       [not found] ` <handler.60980.B.167429057211919.ack@debbugs.gnu.org>
  2023-01-30  8:29 ` bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map Juri Linkov
  0 siblings, 2 replies; 6+ messages in thread
From: Ramesh Nedunchezian @ 2023-01-21  8:37 UTC (permalink / raw)
  To: 60980; +Cc: Juri Linkov

[-- 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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-13 17:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21  8:37 bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map Ramesh Nedunchezian
     [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

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).