emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Configure Helm Source from org-tags-view


From: Jean Louis
Subject: Re: [O] Configure Helm Source from org-tags-view
Date: Thu, 8 Aug 2019 23:20:35 +0200
User-agent: Mutt/1.10.1 (2018-07-13)

* Nathan Neff <address@hidden> [2019-08-08 22:47]:
> Hi Jean Louis,
> 
> Thank you for your time and advice - I am trying to spend time
> learning Elisp and more of the underpinnings in org-mode - so your
> advice was very helpful.
> 
> In fact, I found that org-scan-tags is called by org-map-entries -
> org-map-entries can specify a SCOPE of 'agenda (not the same
> as the 'agenda that's provided to org-scan tags).
> 
> So, I got the code down to a one-liner!
> 
> ;; This searches all agenda-files and returns a bunch of
> ;; stuff that I can re-use in Helm
> (org-map-entries 'agenda bkm 'agenda)

Good if it works for you.

Me, I don't need much programming for Org. What I did for me is
sending assignments by email.

#+PROPERTY: ASSIGNED_ALL John

*** Policies on gold prospecting                                      :staff:
    :PROPERTIES:
    :CREATED:  [2019-05-11 Sat 11:14]
    :ID:       c9c92a1e-7f60-43b0-8dcf-c16ef47dca52
    :ASSIGNED: John
    :END:

Then if I execute the function, it asks me to send email with some
subject to Ezekiel, and he received the Org heading in the email.

That way I am distributing tasks to people who don't have computer,
they read it on phone and do it.

That is what I did with Org mode

 (setq *rcd-org-members-for-assigned-tasks*
       '((1 "John" "Management" "address@hidden" management)

;; Whereby "John" is in :ASSIGNED, then comes email identity, then comes
;; signature and settings for mutt. I use mutt to send auto emails from
;; Emacs.

(defun rcd-org-extract-assigned-member-email-data ()
  "Fetches ASSIGNED individual from subtree and returns the data"
  (let ((assigned (org-entry-get nil "ASSIGNED")))
    (if (not assigned)
        (let* ((individual (completing-read "Receiver:" 
(assigned-members-complete))))
          (let ((id (rcd/org-find-assigned-member-id individual)))
            (if id (rcd/org-find-assigned-member-email-data id)
              nil)))
      (let ((id (rcd/org-find-assigned-member-id assigned)))
        (rcd/org-find-assigned-member-email-data id)))))

(defun rcd-org-subtree-to-file (signature)
  "Saves subtree to file"
  (org-back-to-heading)
  (let* ((filename (concatenate 'string (getenv "TMPDIR") (rcd/file-timestamp) 
".org")))
    (org-copy-subtree)
    (find-file-noselect filename)
    (with-temp-file filename
      (org-mode)
      (yank)
      (insert "\n\n")
      (insert-file-contents signature)
      )
    filename))

(defun rcd/org-find-headline ()
  "Finds current Org headline"
  (org-with-wide-buffer
   (org-back-to-heading t)
   (let ((case-fold-search nil))
     (when (looking-at org-complex-heading-regexp)
       (match-string-no-properties 4)))))

(defun rcd-org-mutt-send-file (name email subject file &optional prefix)
  "Uses mutt to quickly send the file"
  (let* ((prefix (if prefix prefix (mutt/prepared-subject)))
         (to (format "\"%s <%s>\"" name email))
         ;; (to (rcd-mutt-escape-string to))
         (subject (concatenate 'string "\"" prefix ": " subject "\""))
         (command (format "mutt -s %s -i \"%s\" %s" subject file to)))
    (shell-command command)
    (message command)))

(defun mutt/prepared-subject ()
  (let ((subjects '("TASK" "UPDATED" "EXPENSES UPDATED" 
                     "POLICY" "READ THIS" "PROJECT" "QUESTION"))
        (completion-ignore-case t))
    (completing-read "Choose subject: " subjects nil nil)))

(defun assigned-members-complete ()
  (let ((list (loop for i in *rcd-org-members-for-assigned-tasks* collect (cons 
(second i) (second i)))))
    list))

(defun rcd/org-send-assigned-task ()
  "Sends assigned task to designated individual as Org"
  (interactive)
  (let* ((member-data (rcd-org-extract-assigned-member-email-data))
         (id (if member-data (first member-data) nil))
         (signature (if (equal (type-of (symbol-value (fifth member-data))) 
'cons)
                        (third (symbol-value (fifth member-data))) ""))
         (file (rcd-org-subtree-to-file signature))
         (subject (rcd/org-find-headline))
         (esubject (escape-% subject))
         (ask (unless id (y-or-n-p "No assignment found. Do you want to send it 
by email?")))
         (name (if id (third member-data)))
         ;; (name (if ask (read-from-minibuffer "Name:") name))
         (voice (format "The task '%s' is being sent to '%s'" subject name))
         (email (if id (if (equal (type-of (fourth member-data)) 'cons)
                           (car (fourth member-data))
                         (fourth member-data))))
         (email (if ask (cf-search-email (read-from-minibuffer "Search for 
email: ")) email))
         (really (y-or-n-p (format "Do you really want to send it to: %s?" (if 
ask email name)))))
    (if (and really (or id ask))
      (if (string-match "@" email)
        (progn
          ;; (message (escape-% subject))
          (speak voice)
          (rcd-org-mutt-send-file name email esubject file))
        (message "No email specified"))
      (message "Aborted sending."))))

(global-set-key (kbd "C-x 7 o") 'rcd/org-send-assigned-task)

Some functions may be missing. But that is how I send tasks to my
people, it works well.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]