* Custom function for killing the thing at point
@ 2021-08-13 22:29 Rodrigo Morales
2021-08-13 22:46 ` Juan Manuel Macías
2021-08-14 1:45 ` Ihor Radchenko
0 siblings, 2 replies; 5+ messages in thread
From: Rodrigo Morales @ 2021-08-13 22:29 UTC (permalink / raw)
To: emacs-orgmode
I just created this function for copying the thing under the cursor (it
works for some #+BEGIN blocks and links). I think it would be useful for
others, so I'm creating this post for getting feedback on the Elisp code
and sharing it to those interested.
#+BEGIN_SRC elisp
(defun my/org-kill-thing-at-point ()
"Kill the thing at point.
The following things are currently supported
- #+BEGIN_SRC <<any>>
- #+BEGIN_EXPORT <<any>>
- #+BEGIN_EXAMPLE <<any>>
- #+BEGIN_COMMENT
- Org links (the description is not copied)"
(interactive)
(let* (content
(element (org-element-context))
(type (org-element-type element)))
(cond ((or (eq type 'src-block)
(eq type 'export-block)
(eq type 'example-block)
(eq type 'comment-block))
(setq content (plist-get (cadr element) :value)))
((eq type 'link)
(setq content (plist-get (cadr element) :raw-link)))
(t
(error "The element at point couldn't be copied.")))
(my/kill-new content)))
#+END_SRC
#+BEGIN_SRC elisp
(define-key org-mode-map (kbd "C-c c") 'my/org-kill-thing-at-point)
#+END_SRC
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Custom function for killing the thing at point
2021-08-13 22:29 Custom function for killing the thing at point Rodrigo Morales
@ 2021-08-13 22:46 ` Juan Manuel Macías
2021-08-14 1:45 ` Ihor Radchenko
1 sibling, 0 replies; 5+ messages in thread
From: Juan Manuel Macías @ 2021-08-13 22:46 UTC (permalink / raw)
To: Rodrigo Morales; +Cc: orgmode
Hi Rodrigo,
Thanks for sharing, it seems interesting and useful. But I think this
function is missing in your post: `my/kill-new'.
Best regards,
Juan Manuel
Rodrigo Morales writes:
> I just created this function for copying the thing under the cursor (it
> works for some #+BEGIN blocks and links). I think it would be useful for
> others, so I'm creating this post for getting feedback on the Elisp code
> and sharing it to those interested.
>
> #+BEGIN_SRC elisp
> (defun my/org-kill-thing-at-point ()
> "Kill the thing at point.
>
> The following things are currently supported
>
> - #+BEGIN_SRC <<any>>
> - #+BEGIN_EXPORT <<any>>
> - #+BEGIN_EXAMPLE <<any>>
> - #+BEGIN_COMMENT
> - Org links (the description is not copied)"
> (interactive)
> (let* (content
> (element (org-element-context))
> (type (org-element-type element)))
> (cond ((or (eq type 'src-block)
> (eq type 'export-block)
> (eq type 'example-block)
> (eq type 'comment-block))
> (setq content (plist-get (cadr element) :value)))
> ((eq type 'link)
> (setq content (plist-get (cadr element) :raw-link)))
> (t
> (error "The element at point couldn't be copied.")))
> (my/kill-new content)))
> #+END_SRC
>
> #+BEGIN_SRC elisp
> (define-key org-mode-map (kbd "C-c c") 'my/org-kill-thing-at-point)
> #+END_SRC
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Custom function for killing the thing at point
2021-08-13 22:29 Custom function for killing the thing at point Rodrigo Morales
2021-08-13 22:46 ` Juan Manuel Macías
@ 2021-08-14 1:45 ` Ihor Radchenko
2021-08-14 12:33 ` John Kitchin
1 sibling, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2021-08-14 1:45 UTC (permalink / raw)
To: Rodrigo Morales; +Cc: emacs-orgmode
Rodrigo Morales <moralesrodrigo1100@gmail.com> writes:
> (t
> (error "The element at point couldn't be copied.")))
I would fall back to region between :begin and :end of the element.
Also, it might be helpful to print a short message about what element
have just been copied.
Best,
Ihor
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Custom function for killing the thing at point
2021-08-14 1:45 ` Ihor Radchenko
@ 2021-08-14 12:33 ` John Kitchin
2021-08-14 14:09 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: John Kitchin @ 2021-08-14 12:33 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: org-mode-email, Rodrigo Morales
[-- Attachment #1: Type: text/plain, Size: 924 bytes --]
alternatively, fall back to org-mark-element. I am not sure what
differences in what you are trying to achieve and this are, but this should
cover all org elements:
(defun org-kill-element ()
(interactive)
(org-mark-element)
(call-interactively #'kill-region))
John
-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Fri, Aug 13, 2021 at 9:45 PM Ihor Radchenko <yantar92@gmail.com> wrote:
> Rodrigo Morales <moralesrodrigo1100@gmail.com> writes:
>
> > (t
> > (error "The element at point couldn't be copied.")))
>
> I would fall back to region between :begin and :end of the element.
>
> Also, it might be helpful to print a short message about what element
> have just been copied.
>
> Best,
> Ihor
>
>
[-- Attachment #2: Type: text/html, Size: 1680 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Custom function for killing the thing at point
2021-08-14 12:33 ` John Kitchin
@ 2021-08-14 14:09 ` Ihor Radchenko
0 siblings, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2021-08-14 14:09 UTC (permalink / raw)
To: John Kitchin; +Cc: org-mode-email, Rodrigo Morales
John Kitchin <jkitchin@andrew.cmu.edu> writes:
> alternatively, fall back to org-mark-element. I am not sure what
> differences in what you are trying to achieve and this are, but this should
> cover all org elements:
Sounds more reasonable as a default. (org-mark-element) will mark
everything including affiliated keywords and post-blank empty lines.
(:begin .. :end) will not include the affiliated keywords and extra
blank lines.
Best,
Ihor
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-14 14:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-13 22:29 Custom function for killing the thing at point Rodrigo Morales
2021-08-13 22:46 ` Juan Manuel Macías
2021-08-14 1:45 ` Ihor Radchenko
2021-08-14 12:33 ` John Kitchin
2021-08-14 14:09 ` Ihor Radchenko
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.