emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Help with my first elisp
@ 2022-05-22 11:37 Ypo
  2022-05-22 13:27 ` Greg Minshall
  0 siblings, 1 reply; 9+ messages in thread
From: Ypo @ 2022-05-22 11:37 UTC (permalink / raw)
  To: Org-mode

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

Hi


After thinking about learning elisp for years, today I've tried my first 
script. First I made some macros that worked as I intended, and then 
using this tutorial of Protesilaos I was able to transform those macros 
into elisp code.

https://protesilaos.com/codelog/2022-01-31-learning-emacs/
(thanks a lot)


My situation: I am using Protesilaos' package logos, and I would like to 
add to it something (a hook?): to mark the position where my eyesight 
must go. Example:

https://www.tiktok.com/@yporg/video/7100510074342280454?is_from_webapp=1&sender_device=pc&web_id=7100507416085399046


My problems:

  * I don't know how to make my code work always and only when in
    logos-mode.
  * I get those jumps pressing 1, 2 and 3. I would like to use just 1
    key (for example SPACEBAR) not 3 keys to run the function.


My code:


(defun posicion1 ()
   (interactive)
   (next-line 1)
   (beginning-of-visual-line)
   (forward-char 6)
)


(defun posicion2 ()
   (interactive)
   (forward-char 23)
)


(defun posicion3 ()
   (interactive)
   (end-of-visual-line) ;;C-e
   (backward-char 7)
)

(define-key global-map (kbd "1") #'posicion1)
(define-key global-map (kbd "2") #'posicion2)
(define-key global-map (kbd "3") #'posicion3)


Additional problem: I don't know how to recover keys 1, 2 and 3 to their 
normal functioning, right now I can't type 1, 2 or 3 on my Emacs. xD


I think it could be interesting to use just SPC, instead of 1, 2 and 3. 
Maybe it could be done using conditionals, like in this not-working example:

(defvar posicion
   "Position where it is the cursor.")


(defun posicion1 ()
   (interactive)
   (next-line 1)
   (beginning-of-visual-line)
   (forward-char 6)
   (setq posicion 1)
)


(defun posicion2 ()
   (interactive)
   (forward-char 23)
   (setq posicion 2)
)


(defun posicion3 ()
   (interactive)
   (end-of-visual-line) ;;C-e
   (backward-char 7)
   (setq posicion 3)
)




(defun salto ()
   (interactive)
   (if posicion 1
     (posicion2))
   (if posicion 2
     (posicion3))
   (if posicion 3
     (posicion1))
)

(define-key global-map (kbd "SPC") #'salto)



Any help, advice, warning, or menace are welcome.

Best regards :-)

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

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

* Re: Help with my first elisp
  2022-05-22 11:37 Help with my first elisp Ypo
@ 2022-05-22 13:27 ` Greg Minshall
  2022-05-22 14:18   ` Ypo
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Minshall @ 2022-05-22 13:27 UTC (permalink / raw)
  To: Ypo; +Cc: Org-mode

Ypo,

> Additional problem: I don't know how to recover keys 1, 2 and 3 to
> their normal functioning, right now I can't type 1, 2 or 3 on my
> Emacs. xD

you have, e.g.,

> (define-key global-map (kbd "1") #'posicion1)
> (define-key global-map (kbd "2") #'posicion2)
> (define-key global-map (kbd "3") #'posicion3)

but, that is in the global map.  for a given mode, i sometimes do
something like that:

> (add-hook 'mh-show-mode-hook #'(lambda ()
>          (local-set-key "q" 'mh-show-execute-commands)))

or, closer to what you have, sometimes like

>             (define-key mh-letter-mode-map
>              (kbd "C-c s")
>              'ggm-mh-sentaddrs-completion)

i am no elisp expert, and so those are just random things i've found
that work.  but, hopefully this may give you a hint of a direction to
follow.

cheers, Greg


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

* Re: Help with my first elisp
  2022-05-22 13:27 ` Greg Minshall
@ 2022-05-22 14:18   ` Ypo
  2022-05-23 16:46     ` Greg Minshall
  0 siblings, 1 reply; 9+ messages in thread
From: Ypo @ 2022-05-22 14:18 UTC (permalink / raw)
  To: Greg Minshall; +Cc: Org-mode

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

Thanks, Greg

  * Now I am able to run my script every time I am in logos-focus mode :D
  * But my keys don't get to be "normal" after I get out of logos-focus
    mode.

This is how my code is evolving (the "conditional part" is not working yet):

(add-hook 'logos-focus-mode-hook #'(lambda ()

(defvar posicion
   "Position where is the cursor.")

(defun posicion3 ()
   (interactive)
   (end-of-visual-line) ;;C-e
   (backward-char 7)
   (setq posicion 3)
)

(defun posicion2 ()
   (interactive)
   (forward-char 23)
   (setq posicion 2)
)

(defun posicion1 ()
   (interactive)
   (next-line 1)
   (beginning-of-visual-line)
   (forward-char 6)
   (setq posicion 1)
)

(defun salto ()
   (interactive)
   (if posicion 1
     (posicion2)
       (if posicion 2
       (posicion3)
         (if posicion 3
         (posicion1)))))

;; (define-key global-map (kbd "SPC") #'salto)
(local-set-key "j" 'posicion1)
(local-set-key "k" 'posicion2)
(local-set-key "l" 'posicion3)
))


El 22/05/2022 a las 15:27, Greg Minshall escribió:
> Ypo,
>
>> Additional problem: I don't know how to recover keys 1, 2 and 3 to
>> their normal functioning, right now I can't type 1, 2 or 3 on my
>> Emacs. xD
> you have, e.g.,
>
>> (define-key global-map (kbd "1") #'posicion1)
>> (define-key global-map (kbd "2") #'posicion2)
>> (define-key global-map (kbd "3") #'posicion3)
> but, that is in the global map.  for a given mode, i sometimes do
> something like that:
>
>> (add-hook 'mh-show-mode-hook #'(lambda ()
>>           (local-set-key "q" 'mh-show-execute-commands)))
> or, closer to what you have, sometimes like
>
>>              (define-key mh-letter-mode-map
>>               (kbd "C-c s")
>>               'ggm-mh-sentaddrs-completion)
> i am no elisp expert, and so those are just random things i've found
> that work.  but, hopefully this may give you a hint of a direction to
> follow.
>
> cheers, Greg

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

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

* Re: Help with my first elisp
  2022-05-22 14:18   ` Ypo
@ 2022-05-23 16:46     ` Greg Minshall
  2022-05-23 19:38       ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Minshall @ 2022-05-23 16:46 UTC (permalink / raw)
  To: Ypo; +Cc: Org-mode

Ypo,

> (defun salto ()
>   (interactive)
>   (if posicion 1
>     (posicion2)
>       (if posicion 2
>       (posicion3)
>         (if posicion 3
>         (posicion1)))))

your function =salto= may be using =if= incorrectly.  try marking that
=defun= and hitting TAB to justify it.  my guess is, that's not what you
want.

> ;; (define-key global-map (kbd "SPC") #'salto)
> (local-set-key "j" 'posicion1)
> (local-set-key "k" 'posicion2)
> (local-set-key "l" 'posicion3)
> ))

maybe use something like

>>              (define-key mh-letter-mode-map
>>               (kbd "C-c s")
>>               'ggm-mh-sentaddrs-completion)

but, using whatever the name of the logos-focus mode map, pointing at
your functions?

cheers, Greg


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

* Re: Help with my first elisp
  2022-05-23 16:46     ` Greg Minshall
@ 2022-05-23 19:38       ` tomas
  0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2022-05-23 19:38 UTC (permalink / raw)
  To: emacs-orgmode

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

On Mon, May 23, 2022 at 09:46:09AM -0700, Greg Minshall wrote:
> Ypo,
> 
> > (defun salto ()
> >   (interactive)
> >   (if posicion 1

You are comparing the value of posicion to 1?

Then it should probably be "(if (= posicion 1) ...)" or
"(if (equal posicion 1) ...)" or something like that.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Help with my first elisp
@ 2022-05-24 17:30 Kepa Diez
  2022-05-25  6:35 ` Orm Finnendahl
  0 siblings, 1 reply; 9+ messages in thread
From: Kepa Diez @ 2022-05-24 17:30 UTC (permalink / raw)
  To: Org-mode

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


> maybe use something like
>
> >/> (define-key mh-letter-mode-map/
> >/> (kbd "C-c s")/
> >/> 'ggm-mh-sentaddrs-completion)/
>
> but, using whatever the name of the logos-focus mode map, pointing at
> your functions?

Hi Greg

I think "logos" doesn't have a map, is it possible?


> On Mon, May 23, 2022 at 09:46:09AM -0700, Greg Minshall wrote:
> >/Ypo,/
> >//
> >/> (defun salto ()/
> >/> (interactive)/
> >/> (if posicion 1/
>
> You are comparing the value of posicion to 1?
>
> Then it should probably be "(if (= posicion 1) ...)" or
> "(if (equal posicion 1) ...)" or something like that.
>
> Cheers
> -- 
> t
Thanks, Tomas. It seems the "if" part works, now I use my elisp just 
with the spacebar :-)

(add-hook 'logos-focus-mode-hook #'(lambda ()

(defvar posicion
   "Position where is the cursor.")

   (defun focusPointStart ()
   (interactive)
   (next-line 1)
   (beginning-of-visual-line)
   (forward-char 6)
   (setq posicion 1)
)

(defun focusPointInter ()
   (interactive)
   (forward-char 23)
   (setq posicion 2)
)


(defun focusPointEnd ()
   (interactive)
   (end-of-visual-line) ;;C-e
   (backward-char 7)
   (setq posicion 3)
)

(defun focusJump ()
   (interactive)
   (if (equal posicion 1)
     (focusPointInter)
       (if (equal posicion 2)
       (focusPointEnd)
         (if  (equal posicion 3)
         (focusPointStart)))))

(define-key global-map (kbd "SPC") #'focusJump)
))


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

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

* Re: Help with my first elisp
  2022-05-24 17:30 Kepa Diez
@ 2022-05-25  6:35 ` Orm Finnendahl
  2022-05-25  8:24   ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: Orm Finnendahl @ 2022-05-25  6:35 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Am Dienstag, den 24. Mai 2022 um 19:30:40 Uhr (+0200) schrieb Kepa Diez:
> (defun focusJump ()
>   (interactive)
>   (if (equal posicion 1)
>     (focusPointInter)
>       (if (equal posicion 2)
>       (focusPointEnd)
>         (if  (equal posicion 3)
>         (focusPointStart)))))

maybe you want to cleanup a bit:

(defun focusJump (posicion)
  (interactive "nPosicion: ")
  (case posicion
    (1 (focusPointInter))
    (2 (focusPointEnd))
    (3 (focusPointStart))))

BTW: As lisp doesn't distinguish case, it is common practice in lisp
to seperate words in symbols with dashes like 'focus-jump,
'focus-pont-inter, 'focus-point-start, etc.

--
Orm


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

* Re: Help with my first elisp
  2022-05-25  6:35 ` Orm Finnendahl
@ 2022-05-25  8:24   ` tomas
  2022-05-27  7:23     ` Orm Finnendahl
  0 siblings, 1 reply; 9+ messages in thread
From: tomas @ 2022-05-25  8:24 UTC (permalink / raw)
  To: emacs-orgmode

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

On Wed, May 25, 2022 at 08:35:19AM +0200, Orm Finnendahl wrote:
> Hi,
> 
> Am Dienstag, den 24. Mai 2022 um 19:30:40 Uhr (+0200) schrieb Kepa Diez:
> > (defun focusJump ()
> >   (interactive)
> >   (if (equal posicion 1)
> >     (focusPointInter)
> >       (if (equal posicion 2)
> >       (focusPointEnd)
> >         (if  (equal posicion 3)
> >         (focusPointStart)))))
> 
> maybe you want to cleanup a bit:
> 
> (defun focusJump (posicion)
>   (interactive "nPosicion: ")
>   (case posicion
>     (1 (focusPointInter))
>     (2 (focusPointEnd))
>     (3 (focusPointStart))))
> 
> BTW: As lisp doesn't distinguish case, it is common practice in lisp
> to seperate words in symbols with dashes like 'focus-jump,
> 'focus-pont-inter, 'focus-point-start, etc.

Just to avoid confusion: Emacs Lisp does distinguish case. Traditional
Lisp doesn't. I know you know, but people could misunderstand the above.

The rest stands: in Emacs Lisp it's customary to write variable and
function names with dashes, in good ol' Lisp tradition.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Help with my first elisp
  2022-05-25  8:24   ` tomas
@ 2022-05-27  7:23     ` Orm Finnendahl
  0 siblings, 0 replies; 9+ messages in thread
From: Orm Finnendahl @ 2022-05-27  7:23 UTC (permalink / raw)
  To: emacs-orgmode

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

Am Mittwoch, den 25. Mai 2022 um 10:24:01 Uhr (+0200) schrieb tomas@tuxteam.de:
> 
> Just to avoid confusion: Emacs Lisp does distinguish case. Traditional
> Lisp doesn't. I know you know, but people could misunderstand the above.

Yes, that was a bit imprecise ;-)

Best,
Orm
----------------------------------------------------------------------
Prof. Orm Finnendahl
Komposition
Hochschule für Musik und Darstellende Kunst
Eschersheimer Landstr. 29-39
60322 Frankfurt am Main

https://www.youtube.com/watch?v=2rWha1HTfFE&list=PLiGfneJSWmNw6dTUvcTHbTkCYOOTiB_N6


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2022-05-27  7:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-22 11:37 Help with my first elisp Ypo
2022-05-22 13:27 ` Greg Minshall
2022-05-22 14:18   ` Ypo
2022-05-23 16:46     ` Greg Minshall
2022-05-23 19:38       ` tomas
  -- strict thread matches above, loose matches on Subject: below --
2022-05-24 17:30 Kepa Diez
2022-05-25  6:35 ` Orm Finnendahl
2022-05-25  8:24   ` tomas
2022-05-27  7:23     ` Orm Finnendahl

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).