progfolio / doct

DOCT: Declarative Org Capture Templates for Emacs
GNU General Public License v3.0
380 stars 8 forks source link

How to capitalize the text entered from other prompt? #37

Closed Ypot closed 1 year ago

Ypot commented 1 year ago

Hi

I have been referred to this doct package, from de orgmode mail list.

I have read the documentation, but still I don't know how to achieve what I am trying: (I am not a programmer).

Could it be possible, in org-capture, to capitalize the text entered from a previous prompt?

Example: I have this part of an org-capture template:

* %^{CLIENT} _%^{Project}_ /%^{Description}/
:PROPERTIES:
:DIR: z:/! 2023/%\\1-%\\2-%\\3
:END:

I would like to know if it could be possible to “capitalize” the used data that I entered before. For example, instead of this:

** Client _Project Number_ /Project description/
:PROPERTIES:
:DIR: z:/! 2023/Client-Project Number-Project description
:END:

I want to get this: (The 3rd line is “capitalized”)

** Client _Project Number_ /Project description/
:PROPERTIES:
:DIR: z:/! 2023/CLIENT-PROJECT NUMBER-PROJECT DESCRIPTION
:END:

Best regards

progfolio commented 1 year ago

Could it be possible, in org-capture, to capitalize the text entered from a previous prompt?

It's certainly possible. You'd need to write a hook function to manipulate the text after entering it. This isn't really DOCT specific, but DOCT makes it much easier to manage these types of hooks. e.g.

(doct `("test" :keys "t"
        :file "/tmp/test.org"
        :hook
        ,(defun +org-capture-captialize-dir-prop ()
           (save-excursion
             (goto-char (point-min))
             (when (re-search-forward "^:DIR:" nil t)
               (upcase-region (line-beginning-position) (line-end-position)))))
        :template ("* %^{CLIENT} _%^{Project}_ /%^{Description}/"
                   ":PROPERTIES:"
                   ":DIR: z:/! 2023/%\\1-%\\2-%\\3"
                   ":END:")))

Testing below:

(progn
  (require 'org-capture)
  (let ((org-capture-templates
         (doct `("test" :keys "t"
                 :file "/tmp/test.org"
                 :hook
                 ,(defun +org-capture-captialize-dir-prop ()
                    (save-excursion
                      (goto-char (point-min))
                      (when (re-search-forward "^:DIR:" nil t)
                        (upcase-region (line-beginning-position) (line-end-position)))))
                 :template ("* %^{CLIENT} _%^{Project}_ /%^{Description}/"
                            ":PROPERTIES:"
                            ":DIR: z:/! 2023/%\\1-%\\2-%\\3"
                            ":END:")))))
    (org-capture nil "t")))

Filling out the template prompts with "testing" "one" "two" results in:

* testing _one_ /two/
:PROPERTIES:
:DIR: Z:/! 2023/TESTING-ONE-TWO
:END:

Hope that helps.

progfolio commented 1 year ago

If you're having trouble (it looks like you deleted your comment, so maybe not) please be specific about how it doesn't work.

Ypot commented 1 year ago

Firstly, was I used doct '( insted of doct `( Then, I have tried to mix existing org-capture-templates with the new doct template. Now I am trying:


(setopt org-capture-templates
(doct-add-to org-capture-templates
         `("Proyecto" :keys "y"
           :type entry
               :id "2023-02-09T12:06:10,23"
               :prepend t
           :immediate-finish t
           :jump-to-captured t
           :hook
               ,(defun +org-capture-captialize-dir-prop ()
                  (save-excursion
                    (goto-char (point-min))
                    (when (re-search-forward "^:DIR:" nil t)
                      (upcase-region (line-beginning-position) (line-end-position)))))         
           :template ("* PROY %^{CLIENTE} _%^{OT}_ /%^{Descripción}/
:PROPERTIES:
:DIR: z:/! 2023/COMERCIAL/OFERTAS/%\\1-%\\2-%\\3
:END:
** Gestión del Proyecto
*** Contacto
*** Datos de partida
*** Reunión %\\1
*** SIG. Ofertar
*** T-AD Facturar")
           'append)))

But it is unrelated with the opened issue.