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

* bug#60980: Acknowledgement (FR: It would be useful to have a repeat-exit-function for a repeat-map)
       [not found] ` <handler.60980.B.167429057211919.ack@debbugs.gnu.org>
@ 2023-01-21  8:46   ` Ramesh Nedunchezian
  0 siblings, 0 replies; 6+ messages in thread
From: Ramesh Nedunchezian @ 2023-01-21  8:46 UTC (permalink / raw)
  To: 60980

[-- Attachment #1: Type: text/plain, Size: 118 bytes --]

I am attaching the `*lossage*` file generated by the video recording at https://github.com/rnchzn/scratch/issues/1




[-- Attachment #2: lossage.txt --]
[-- Type: text/plain, Size: 1380 bytes --]

 M-x			     ;; execute-extended-command
 l			     ;; self-insert-command
 o			     ;; self-insert-command
 a			     ;; self-insert-command
 -			     ;; self-insert-command
 f			     ;; self-insert-command
 <backspace>		     ;; delete-backward-char
 <backspace>		     ;; delete-backward-char
 d			     ;; self-insert-command
 -			     ;; self-insert-command
 f			     ;; self-insert-command
 i			     ;; self-insert-command
 l			     ;; self-insert-command
 e			     ;; self-insert-command
 <return>		     ;; minibuffer-complete-and-exit
 t			     ;; self-insert-command
 h			     ;; self-insert-command
 i			     ;; self-insert-command
 n			     ;; self-insert-command
 g			     ;; self-insert-command
 .			     ;; self-insert-command
 e			     ;; self-insert-command
 l			     ;; self-insert-command
 <return>		     ;; minibuffer-complete-and-exit
 s-l .			     ;; symbol-thing-forward
 s-l			     ;; symbol-thing-forward
 s-l			     ;; symbol-thing-forward
 s-l			     ;; symbol-thing-forward
 s-j			     ;; symbol-thing-backward
 s-j			     ;; symbol-thing-backward
 s-i			     ;; sexp-thing-up
 s-l			     ;; sexp-thing-forward
 s-l			     ;; sexp-thing-forward
 s-i			     ;; sexp-thing-up
 s-l			     ;; sexp-thing-forward
 s-l			     ;; sexp-thing-forward
 s-j			     ;; sexp-thing-backward
 s-j			     ;; sexp-thing-backward
 <return>		     ;; newline
 C-/			     ;; undo

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

* bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map
  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-30  8:29 ` Juri Linkov
  2023-02-12  4:58   ` Ramesh Nedunchezian
  2023-02-13 17:47   ` Juri Linkov
  1 sibling, 2 replies; 6+ messages in thread
From: Juri Linkov @ 2023-01-30  8:29 UTC (permalink / raw)
  To: Ramesh Nedunchezian; +Cc: 60980

Thanks for the feature request.

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

The problem with the symbol property name `repeat-exit-function` is that
the existing variable `repeat-exit-function` has another purpose.

For example, for `repeat-exit-timeout` there is the global variable
and the symbol property with the same names because they are doing
the same thing.

But the variable `repeat-exit-function` is different.  It's not
customizable by the user.  So another name would be preferable.

> 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

Indeed, before adding a new symbol property could you please try to use
the existing `repeat-echo-function`.  It's called with the nil argument
on exit.  Do you need a symbol property `repeat-echo-function`, or can use
the global variable, e.g. by checking some buffer-local variable in it?





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

* bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map
  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
  1 sibling, 1 reply; 6+ messages in thread
From: Ramesh Nedunchezian @ 2023-02-12  4:58 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60980

[-- Attachment #1: Type: text/plain, Size: 2401 bytes --]


On 30/01/23 13:59, Juri Linkov wrote:
> Thanks for the feature request.
>
>> 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)
> The problem with the symbol property name `repeat-exit-function` is that
> the existing variable `repeat-exit-function` has another purpose.
>
> For example, for `repeat-exit-timeout` there is the global variable
> and the symbol property with the same names because they are doing
> the same thing.
>
> But the variable `repeat-exit-function` is different.  It's not
> customizable by the user.  So another name would be preferable.
>
>> 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
> Indeed, before adding a new symbol property could you please try to use
> the existing `repeat-echo-function`.  It's called with the nil argument
> on exit.  Do you need a symbol property `repeat-echo-function`, or can use
> the global variable, e.g. by checking some buffer-local variable in it?

I don't need exit function per-map.

I can use the "global" `repeat-echo-function' to clean up after the
`repeat-map`'s exit, like this:

    (add-function
     :after repeat-echo-function
     (defun thing-exit-function (keymap)
       (cond
        (keymap (ignore))
        (t (thing-unhighlight)))))


You have addressed my main concern.  You may close the bug.
    

Some remarks.

1. You may consider introducing a
   `repeat-enter/leave-function`---globally, AND per-map--- and plugin
   the existing `repeat-echo-function` in to that.

   IOW, the "existing" `repeat-echo-function` is a generic enter/leave
   dispatcher for all `repeat-maps`.
   
2. (I believe) introducing an "enter"/"leave" function per-repeat map
   is a much cleaner approach, and could be put to good use by users.

FWIW, the video I linked https://github.com/rnchzn/scratch/issues/1 is
my own take on what `objed` (https://github.com/clemera/objed) does.


[-- Attachment #2: Type: text/html, Size: 3207 bytes --]

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

* bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map
  2023-02-12  4:58   ` Ramesh Nedunchezian
@ 2023-02-12 17:23     ` Juri Linkov
  0 siblings, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2023-02-12 17:23 UTC (permalink / raw)
  To: Ramesh Nedunchezian; +Cc: 60980

> You have addressed my main concern.  You may close the bug.
>
> Some remarks.
>
> 1. You may consider introducing a
>    `repeat-enter/leave-function`---globally, AND per-map--- and plugin
>    the existing `repeat-echo-function` in to that.
>
>    IOW, the "existing" `repeat-echo-function` is a generic enter/leave
>    dispatcher for all `repeat-maps`.
>
> 2. (I believe) introducing an "enter"/"leave" function per-repeat map
>    is a much cleaner approach, and could be put to good use by users.

Thanks for the ideas.  I'll leave this feature request open for some time
to see if we could implement such a global and keymap-local hooks to run
on entering/leaving the repeating sequence.

> FWIW, the video I linked https://github.com/rnchzn/scratch/issues/1 is
> my own take on what `objed` (https://github.com/clemera/objed) does.

The video looks nice, so you may consider creating a new package that
will do something like `objed` does, but with using `repeat-mode`.





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

* bug#60980: FR: It would be useful to have a repeat-exit-function for a repeat-map
  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-13 17:47   ` Juri Linkov
  1 sibling, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2023-02-13 17:47 UTC (permalink / raw)
  To: 60980

> The problem with the symbol property name `repeat-exit-function` is that
> the existing variable `repeat-exit-function` has another purpose.
>
> For example, for `repeat-exit-timeout` there is the global variable
> and the symbol property with the same names because they are doing
> the same thing.
>
> But the variable `repeat-exit-function` is different.  It's not
> customizable by the user.  So another name would be preferable.

This internal variable is renamed now in emacs-29.
So in master we could use this name to implement new feature.





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