emacs-async icon indicating copy to clipboard operation
emacs-async copied to clipboard

Cannot use mark/region

Open timmli opened this issue 10 months ago • 2 comments
trafficstars

I'm trying to use async (v1.9.9) to export iCal/ics files from Org in the background. Everything works well except for the handling of marks and regions. Specifially, the following code is not executed as expected:

(org-mark-subtree)
(org-icalendar-export-to-ics nil t)

Within async, (org-mark-subtree) does not create a region – I've checked that (region-active-p) is nil –, and therefore (org-icalendar-export-to-ics nil t) does not export anything. Needless to say, without async there is no such problem.

Is this a bug or a feature of async?

timmli avatar Jan 12 '25 09:01 timmli

Timm Lichte @.***> writes:

  1. ( ) text/plain (*) text/html

I'm trying to use async (v1.9.9) to export iCal/ics files from Org in the background. Everything works well except for the handling of marks and regions. Specifially, the following code is not executed as expected:

(org-mark-subtree) (org-icalendar-export-to-ics nil t)

I know nothing about these org functions, but how do you want the emacs child process be aware of your region if you doesn't pass the contents to it? For marks, you can't pass them to child process, they are special objects (like buffers, windows etc..).

-- Thierry

thierryvolpiatto avatar Jan 12 '25 09:01 thierryvolpiatto

Thanks for your help! I forgot to explicitly activate transient-mark-mode in the async process, like in the following MWE.

(let ((test '(lambda ()
               (with-temp-buffer
                 ;; (transient-mark-mode 1)
                 (insert "Marked region")
                 (push-mark (point-min))
                 (goto-char (point-max))
                 (setq mark-active t)
                 (region-active-p)))))
  (async-start
   ;; What to do in the child process
   `(lambda ()
      (funcall ,test)) ; --> nil

   ;; What to do when it finishes
   `(lambda (result)
      (message "Async process done, result should be %s: %s"
               (funcall ,test) ; --> t
               result))))

region-active-p checks both "if Transient Mark mode is enabled and the mark is active".

I think you can close this issue.

timmli avatar Jan 12 '25 12:01 timmli