emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* RFC on implementation adding buttons beside headings
@ 2023-02-18 16:00 pareto optimal
  2023-02-18 16:01 ` pareto optimal
  2023-02-19 11:04 ` Ihor Radchenko
  0 siblings, 2 replies; 6+ messages in thread
From: pareto optimal @ 2023-02-18 16:00 UTC (permalink / raw)
  To: Emacs Orgmode

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

Hi all!

I've recently been playing with emacs on Android and wanted an easier way to clock in.

My idea was to put buttons beside org headings that are TODO items. I do this by:

- removing clocking buttons on heading if present, then adding a clock in button on 'org-after-todo-state-change-hook`

- removing clocking buttons on heading if present, then adding a clock out button on 'org-clock-in-hook

- removing clocking buttons on heading if present, then adding a clock in button on 'org-clock-out-hook

Well, the removing part isn't quite implemented yet but that's the idea. Otherwise what I'll paste below is a working implementation.

I'm new to using buttons and emacs and I found the only way to place the button where I wanted was to insert some blank space after the heading. Is that expected and best practice or is there some other way to do it?

Would this be something useful in core org-mode? I know at least a few friends who've asked me "why isn't there some button I can click by headings to clock in" when I showed them how I use org-mode.

I also welcome any other ideas or comments.

Thank you for your time.

ParetoOptimalDev
https://www.paretooptimal.dev/

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

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

* Re: RFC on implementation adding buttons beside headings
  2023-02-18 16:00 RFC on implementation adding buttons beside headings pareto optimal
@ 2023-02-18 16:01 ` pareto optimal
  2023-02-20 19:17   ` Bruno Barbier
  2023-02-19 11:04 ` Ihor Radchenko
  1 sibling, 1 reply; 6+ messages in thread
From: pareto optimal @ 2023-02-18 16:01 UTC (permalink / raw)
  To: Emacs Orgmode

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

I forgot the implementation:

```
(define-button-type 'org-clock-in-button
  'follow-link t
  'face 'custom-button
  'mouse-face 'custom-button-mouse
  'action (lambda (b) (org-clock-in)))

(define-button-type 'org-clock-out-button
  'follow-link t
  'face 'custom-button
  'mouse-face 'custom-button-mouse
  'action (lambda (b) (org-clock-out)))

(defun has-clock-in-button ()
  (s-contains? "Clock In" (nth 4 (org-heading-components))))

 (defun has-clock-out-button ()
  (s-contains? "Clock Out" (nth 4 (org-heading-components))))

(defun pod/add-clock-in-button-to-right-of-heading ()
  (unless (has-clock-in-button)
  (save-excursion
    (org-end-of-line)
    (let ((end-of-line-before-insert (point)))
      (insert "    Clock In")
      (let* ((button-start (+ 4 end-of-line-before-insert))
	    (button-end (+ 8 button-start)))
	(make-button button-start button-end :type 'org-clock-in-button))))))

;; (defun remove-clock-in-button ()
;; )

(defun pod/add-clock-out-button-to-right-of-heading ()
  (unless (has-clock-out-button)
  (outline-up-heading)
  ;; (remove-clock-in-button)
  (save-excursion
    (org-end-of-line)
    (let ((end-of-line-before-insert (point)))
      (insert "    Clock Out")
      (let* ((button-start (+ 4 end-of-line-before-insert))
	    (button-end (+ 9 button-start)))
	(make-button button-start button-end :type 'org-clock-out-button))))))

(add-hook 'org-after-todo-state-change-hook #'pod/add-clock-in-button-to-right-of-heading)

(add-hook 'org-clock-in-hook #'pod/add-clock-out-button-to-right-of-heading)

(add-hook 'org-clock-out-hook #'pod/add-clock-in-button-to-right-of-heading)
```

On Feb 18, 2023 at 10:00 AM, pareto optimal <pareto.optimal@mailfence.com> wrote:
Hi all!

I've recently been playing with emacs on Android and wanted an easier way to clock in.

My idea was to put buttons beside org headings that are TODO items. I do this by:

- removing clocking buttons on heading if present, then adding a clock in button on 'org-after-todo-state-change-hook`

- removing clocking buttons on heading if present, then adding a clock out button on 'org-clock-in-hook

- removing clocking buttons on heading if present, then adding a clock in button on 'org-clock-out-hook

Well, the removing part isn't quite implemented yet but that's the idea. Otherwise what I'll paste below is a working implementation.

I'm new to using buttons and emacs and I found the only way to place the button where I wanted was to insert some blank space after the heading. Is that expected and best practice or is there some other way to do it?

Would this be something useful in core org-mode? I know at least a few friends who've asked me "why isn't there some button I can click by headings to clock in" when I showed them how I use org-mode.

I also welcome any other ideas or comments.

Thank you for your time.

ParetoOptimalDev
https://www.paretooptimal.dev/

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

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

* Re: RFC on implementation adding buttons beside headings
  2023-02-18 16:00 RFC on implementation adding buttons beside headings pareto optimal
  2023-02-18 16:01 ` pareto optimal
@ 2023-02-19 11:04 ` Ihor Radchenko
  2023-02-19 22:57   ` Samuel Wales
       [not found]   ` <292424133.47705.1676856972523@fidget.co-bxl>
  1 sibling, 2 replies; 6+ messages in thread
From: Ihor Radchenko @ 2023-02-19 11:04 UTC (permalink / raw)
  To: pareto optimal; +Cc: Emacs Orgmode

pareto optimal <pareto.optimal@mailfence.com> writes:

> I've recently been playing with emacs on Android and wanted an easier way to clock in.
>
> My idea was to put buttons beside org headings that are TODO items. I do this by:
>
> - removing clocking buttons on heading if present, then adding a clock in button on 'org-after-todo-state-change-hook`
> ...

Alternatives can be:
1. Showing a side buffer with context-dependent buttons
2. Utilizing context menu

> I'm new to using buttons and emacs and I found the only way to place the button where I wanted was to insert some blank space after the heading. Is that expected and best practice or is there some other way to do it?

AFAIK, buttons must be on top of actual text.
You can also use `insert-button'.

> Would this be something useful in core org-mode? I know at least a few friends who've asked me "why isn't there some button I can click by headings to clock in" when I showed them how I use org-mode.

Mobile support will certainly be useful.

Though I'd prefer not to modify the buffer and instead use a
side window. That way, you can write a minor mode that will create
configurable buttons depending on major mode and cursor position in the
buffer. The buttons will also have a fixed size, possibly utilizing
larger fonts-a useful thing to have on smartphones.

Such minor mode may then be not restricted to Org mode and could be
used, say, in Org agenda or other major modes in Emacs.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: RFC on implementation adding buttons beside headings
  2023-02-19 11:04 ` Ihor Radchenko
@ 2023-02-19 22:57   ` Samuel Wales
       [not found]   ` <292424133.47705.1676856972523@fidget.co-bxl>
  1 sibling, 0 replies; 6+ messages in thread
From: Samuel Wales @ 2023-02-19 22:57 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: pareto optimal, Emacs Orgmode

at least for context menus or so it might or might not be useful to
install and modify org-mouse.  it allows you to do things like unfold,
check a list box, etc.

On 2/19/23, Ihor Radchenko <yantar92@posteo.net> wrote:
> pareto optimal <pareto.optimal@mailfence.com> writes:
>
>> I've recently been playing with emacs on Android and wanted an easier way
>> to clock in.
>>
>> My idea was to put buttons beside org headings that are TODO items. I do
>> this by:
>>
>> - removing clocking buttons on heading if present, then adding a clock in
>> button on 'org-after-todo-state-change-hook`
>> ...
>
> Alternatives can be:
> 1. Showing a side buffer with context-dependent buttons
> 2. Utilizing context menu
>
>> I'm new to using buttons and emacs and I found the only way to place the
>> button where I wanted was to insert some blank space after the heading. Is
>> that expected and best practice or is there some other way to do it?
>
> AFAIK, buttons must be on top of actual text.
> You can also use `insert-button'.
>
>> Would this be something useful in core org-mode? I know at least a few
>> friends who've asked me "why isn't there some button I can click by
>> headings to clock in" when I showed them how I use org-mode.
>
> Mobile support will certainly be useful.
>
> Though I'd prefer not to modify the buffer and instead use a
> side window. That way, you can write a minor mode that will create
> configurable buttons depending on major mode and cursor position in the
> buffer. The buttons will also have a fixed size, possibly utilizing
> larger fonts-a useful thing to have on smartphones.
>
> Such minor mode may then be not restricted to Org mode and could be
> used, say, in Org agenda or other major modes in Emacs.
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


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

* Re: RFC on implementation adding buttons beside headings
       [not found]   ` <292424133.47705.1676856972523@fidget.co-bxl>
@ 2023-02-20 13:23     ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2023-02-20 13:23 UTC (permalink / raw)
  To: pareto optimal; +Cc: emacs-orgmode

[ Adding Org ML back to CC ]

pareto optimal <pareto.optimal@mailfence.com> writes:

> Do you mean something like extending https://github.com/alphapapa/org-sidebar to have these instead of directly in the org document?

A bit different.
What I have in mind is something like

(defun yant/insert-interative-button (text window command)
  "Create button named TEXT running COMMAND in WINDOW."
  (insert-button
   text
   'face '(:box t :height 2.0)
   'follow-link t
   'action
   `(lambda (_)
      (select-window ,window)
      (call-interactively #',command))))

(defun yant/demo-buttons ()
  "Demo of a buffer with touch screen-compatible buttons."
  (interactive)
  (unless (derived-mode-p 'org-mode)
    (user-error "Must be in Org mode buffer"))
  (let ((org-window (selected-window)))
    (switch-to-buffer-other-window (get-buffer-create "*Touch buttons*"))
    (with-silent-modifications
      (erase-buffer))
    (yant/insert-interative-button
     "Next heading" org-window 'org-next-visible-heading)
    (insert "\n")
    (yant/insert-interative-button
     "Previous heading" org-window 'org-previous-visible-heading)
    (read-only-mode t)))

> The context menus are great! However it seems some people have a hard time thinking of emacs as a gui applicaiton and right clicking even after I tell them :)

It will be more natural on Android.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: RFC on implementation adding buttons beside headings
  2023-02-18 16:01 ` pareto optimal
@ 2023-02-20 19:17   ` Bruno Barbier
  0 siblings, 0 replies; 6+ messages in thread
From: Bruno Barbier @ 2023-02-20 19:17 UTC (permalink / raw)
  To: pareto optimal, Emacs Orgmode

pareto optimal <pareto.optimal@mailfence.com> writes:

> I found the only way to place the button where I wanted was to insert
> some blank space after the heading. Is that expected and best practice
> or is there some other way to do it?

FWIW, instead of inserting some blank spaces, you could overlay existing
characters, you'll just need to re-inject them at display time so that
the display doesn't change. That way, you don't modified the text.


Here is a way to add a button, in place, without modifying the
buffer.  The trick is to overlay the EOL and to re-inject an EOL
using the "after-string" property.


     (with-current-buffer (generate-new-buffer "=test")
       (cl-flet ((run (f) (lambda (&rest args) (interactive) (funcall f))))
         (let (pos)
           (insert "* My title\n")
           (setq pos (1- (point)))
           (insert "An amazing note.\n\n")
           (insert "** My 2 title\n")
           (insert "An even more amazing note.\n")
           (org-mode)
           (make-button pos (1+ pos)
                        'before-string "\n\n    "
                        'display '((height 2) "Click me!")
                        'after-string "\n\n"
                        'face 'custom-button
                        'action (run (lambda () (message "Thanks!")))
                        )))
       (pop-to-buffer (current-buffer))
       )
       
Note that the above expression requires lexical-binding.


Bruno


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

end of thread, other threads:[~2023-02-20 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 16:00 RFC on implementation adding buttons beside headings pareto optimal
2023-02-18 16:01 ` pareto optimal
2023-02-20 19:17   ` Bruno Barbier
2023-02-19 11:04 ` Ihor Radchenko
2023-02-19 22:57   ` Samuel Wales
     [not found]   ` <292424133.47705.1676856972523@fidget.co-bxl>
2023-02-20 13:23     ` Ihor Radchenko

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