unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* transient questions
@ 2023-03-14  0:05 Joost Kremers
  2023-03-14  1:15 ` triple-backquote (was: Re: transient questions) Emanuel Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Joost Kremers @ 2023-03-14  0:05 UTC (permalink / raw)
  To: gnu-emacs-help

Hi all,

I'm in the process of translating my hydras to transient, mainly to learn a bit
about how transients work, and I'm running into something I don't get.

I've concocted the following:

```
(transient-define-prefix jk-move-transient ()
  :transient-non-suffix #'transient--do-leave
  [:class transient-row
          ("SPC" "" scroll-up-command :transient t)
          ("C-v" "" scroll-up-command :transient t)
          ("<backspace>" "" scroll-down-command :transient t)
          ("M-v" "" scroll-down-command :transient t)
          ("<up>" "" scroll-up-line :transient t)
          ("<down>" "" scroll-down-line :transient t)
          ("<left>" "" scroll-right :transient t)
          ("<right>" "" scroll-left :transient t)
          ("b" "(Un)set bookmark" bm-toggle :transient t)
          ("g" "Top of buffer" beginning-of-buffer :transient t)
          ("G" "End of buffer" end-of-buffer :transient t)
          ("l" "Goto line" consult-goto-line)
          ("m" "Goto mark" consult-mark)
          ("n" "Next bookmark" bm-next)
          ("o" "Outline" consult-outline)
          ("t" "Previous bookmark" bm-previous)
          ("z" "Avy line" avy-goto-line)])
```

From how I understand the manual, the line

    :transient-non-suffix #'transient--do-leave

Should allow non-suffix keys to exit the transient and be executed. That doesn't
seem to work, though. When I type a non-suffix key, the command bound to it does
get executed, (I can move the cursor with C-n, C-p, etc.), but the transient
stays active. So I'm wondering what I'm misunderstanding here and if there's a
way to get what I want. (Which is that any key not bound in the transient exits
the transient and gets executed.)

Secondly, I was wondering if there's a way to call a transient suffix directly,
have it executed and activate the transient. In a hydra, you can bind not only
the body of the hydra but also its heads to keys. The hydra on which the
transient above is modelled, is this:

```
(defhydra jk-move-hydra (:hint nil)
  "Jump"
  ("SPC" scroll-up-command)
  ("C-v" scroll-up-command)
  ("<backspace>" scroll-down-command)
  ("M-v" scroll-down-command)
  ("<up>" scroll-up-line)
  ("<down>" scroll-down-line)
  ("<left>" scroll-right)
  ("<right>" scroll-left)
  ("b" bm-toggle "(Un)set bookmark")
  ("g" beginning-of-buffer "Top of buffer")
  ("G" end-of-buffer "End of buffer")
  ("l" consult-goto-line "Goto line")
  ("m" consult-mark "Goto mark")
  ("n" bm-next "Next bookmark")
  ("o" consult-outline)
  ("t" bm-previous "Previous bookmark")
  ("z" avy-goto-line "Avy line"))

(bind-key "C-v" #'jk-move-hydra/scroll-up-command)
(bind-key "M-v" #'jk-move-hydra/scroll-down-command)
(bind-key "M-g" #'jk-move-hydra/body)
(bind-key "M-G" #'jk-move-hydra/end-of-buffer)
```

I've bound `M-g` to the body of the hydra (the prefix, in transient parlance),
but also a few other keys to heads (suffixes, in transient parlance). With this
setup, `C-v` will execute `jk-move-hydra/scroll-up-command` (i.e.,
`scroll-up-command`) plus activate the hydra.

Is something similar possible with transients? I haven't been able to find
anything like it, but perhaps I'm just not looking in the right place.

TIA


-- 
Joost Kremers
Life has its moments



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

* triple-backquote (was: Re: transient questions)
  2023-03-14  0:05 transient questions Joost Kremers
@ 2023-03-14  1:15 ` Emanuel Berg
  2023-03-15  9:25   ` Ruijie Yu via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 3+ messages in thread
From: Emanuel Berg @ 2023-03-14  1:15 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers wrote:

> ```
> (transient-define-prefix jk-move-transient ()
>   :transient-non-suffix #'transient--do-leave
>   [:class transient-row
>           ("SPC" "" scroll-up-command :transient t)
>           ("C-v" "" scroll-up-command :transient t)
>           ("<backspace>" "" scroll-down-command :transient t)
>           ("M-v" "" scroll-down-command :transient t)
>           ("<up>" "" scroll-up-line :transient t)
>           ("<down>" "" scroll-down-line :transient t)
>           ("<left>" "" scroll-right :transient t)
>           ("<right>" "" scroll-left :transient t)
>           ("b" "(Un)set bookmark" bm-toggle :transient t)
>           ("g" "Top of buffer" beginning-of-buffer :transient t)
>           ("G" "End of buffer" end-of-buffer :transient t)
>           ("l" "Goto line" consult-goto-line)
>           ("m" "Goto mark" consult-mark)
>           ("n" "Next bookmark" bm-next)
>           ("o" "Outline" consult-outline)
>           ("t" "Previous bookmark" bm-previous)
>           ("z" "Avy line" avy-goto-line)])
> ```

Alright, so what is this syntax/feature called, you put Elisp
between an opening/closing triplet backquote and you get font
lock with `gnus-article-mode'?

I like it, let's try it!

```
;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/abc.el

(require 'cl-lib)

(defun alphabet (&optional as-list)
  (let ((abc "a b c d e f g h i j k l m n o p q r s t u v w x y z"))
    (if as-list
        (cl-remove ?\s (string-to-list abc))
      abc) ))
;; (alphabet)   ; a b c d e f g h i j k l m n o p q r s t u v w x y z
;; (alphabet t) ; (97 98 99 100 101 102 103 104 105 106 107 108 ...)

(defun echo-alphabet (&optional num)
  (interactive "P")
  (or num (setq num (length (alphabet t))))
  (let*((part       (cl-subseq (alphabet t) 0 num))
        (str-list   (cl-mapcar (lambda (c) (char-to-string c)) part))
        (str-almost (format "%s" str-list))
        (str        (substring str-almost 1 (1- (length str-almost)))) )
    (message str) ))
;; (echo-alphabet)     ; a b c d e f g h i j k l m n o p q r s t u v w x y z
;; (echo-alphabet  10) ; a b c d e f g h i j
;; (echo-alphabet -10) ; a b c d e f g h i j k l m n o p
(defalias 'abc #'echo-alphabet)

(provide 'abc)
```

So did it work?

Maybe this will improve the level of the information
interchange, or what do you think?

Beautify the moment!

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: triple-backquote (was: Re: transient questions)
  2023-03-14  1:15 ` triple-backquote (was: Re: transient questions) Emanuel Berg
@ 2023-03-15  9:25   ` Ruijie Yu via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 3+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-03-15  9:25 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


Emanuel Berg <incal@dataswamp.org> writes:

> Joost Kremers wrote:
>
>> ```
>> [...]
>> ```
>
> Alright, so what is this syntax/feature called, you put Elisp
> between an opening/closing triplet backquote and you get font
> lock with `gnus-article-mode'?
>
> I like it, let's try it!
>
> ```
> [...]
> ```
>
> So did it work?

Curiously, yours was not colored by my mu4e viewer, whereas Joost's was.
The triple quotes notation originates from markdown (who may have
inherited it from another source, IDK).

Apparently specifying the language explicitly also helps to color your
code block.

    This is not colored:
```
;;; -*- lexical-binding: t -*-
;;
(defun foo ()
  (message "Bar"))
```

    But this is:
```emacs-lisp
;;; -*- lexical-binding: t -*-
;;
(defun foo ()
  (message "Bar"))
```

For other languages it's kind of hit-and-miss -- this only depends on
whether the mail client dev(s) feels like coloring these languages.
Mu4e doesn't color the following blocks, but maybe gnus would.

```c
int main(void) { return 1; }
```

```rust
fn main() { println!(); }
```

--
Best,


RY



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

end of thread, other threads:[~2023-03-15  9:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14  0:05 transient questions Joost Kremers
2023-03-14  1:15 ` triple-backquote (was: Re: transient questions) Emanuel Berg
2023-03-15  9:25   ` Ruijie Yu via Users list for the GNU Emacs text editor

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