Re: [RFC] DOCT: Declarative Org Capture Templates (easier template syntax)

2022-03-23 Thread João Pedro de Amorim Paula
On 20 March 2022 18:19, Ihor Radchenko  wrote:

> Also, if anyone agrees with my arguments below, do not stay silent and
> drop a "+1" email below. Otherwise, this whole thing will be stalled.
> There is no point discussing technical aspects, if there is no interest.

It isn't really something that bothers me, or causes my any sort of
problems, given that I have the same set of capture templates for close
to 3 years now, and have never felt the need to change it.

That being said, getting to those capture templates was a pain indeed,
having to, as you alluded to in another e-mail, constantly revisit the
docstring for the precise position of each element, and more often than
not getting them wrong. So I'm all up for it!

Cheers,

-- 
João Pedro de A. Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Move or rename a file in a link

2022-03-22 Thread João Pedro de Amorim Paula
On 19 March 2022 11:25, Juan Manuel Macías  wrote:

> #+begin_src emacs-lisp
>   (defun my-org-rename-link-file-at-point ()
> (interactive)
> (let* ((curr-dir (if (equal (org-element-property :type 
> (org-element-context)) "attachment")
>(concat (abbreviate-file-name (org-attach-dir)) "/")
>  (abbreviate-file-name default-directory)))
>  (current-path (if (equal (org-element-property :type 
> (org-element-context)) "attachment")
>(concat curr-dir (org-element-property :path 
> (org-element-context)))
>  (org-element-property :path (org-element-context
>  (new-path (read-file-name "Rename file at point to: " current-path)))
>   (rename-file current-path new-path)
>   (message (concat "moved to: " new-path))
>   (if (directory-name-p new-path)
> (setq new-path (concat new-path (file-name-nondirectory 
> current-path)))
>   (setq new-path new-path))
>   (if (equal (org-element-property :type (org-element-context)) 
> "attachment")
> (my-org-replace-link-file (file-name-nondirectory current-path)
>   (replace-regexp-in-string
>curr-dir "" new-path))
>   (my-org-replace-link-file current-path
> (replace-regexp-in-string
>  curr-dir "" new-path)
>
>   (defun my-org-replace-link-file (from to)
> (save-excursion
>   (goto-char (point-min))
>   (while (re-search-forward org-bracket-link-regexp nil t)
>   (cond ((string-match-p (concat "attachment:" from) (match-string 1))
>  (replace-match (concat "[[attachment:" to "]]")))
> ((string-match-p from (match-string 1))
>  (replace-match (concat "[[file:" to "]]")))
> #+end_src

Just a couple of fixes and it seems to be working fine.

diff -u a/org-rename-link.el b/org-rename-link.el

--- a/org-rename-link.el	2022-03-22 12:08:45.790727092 -0300
+++ b/org-rename-link.el	2022-03-22 12:25:31.500218923 -0300
@@ -23,8 +23,11 @@
 (defun my-org-replace-link-file (from to)
   (save-excursion
 (goto-char (point-min))
-(while (re-search-forward org-bracket-link-regexp nil t)
-  (cond ((string-match-p (concat "attachment:" from) (match-string 1))
- (replace-match (concat "[[attachment:" to "]]")))
-((string-match-p from (match-string 1))
- (replace-match (concat "[[file:" to "]]")))
+(while (re-search-forward org-link-bracket-re nil t)
+  (replace-match
+   (cond
+((string-match-p (format "^attachment:%s\\'" from) (match-string 1))
+ (format "attachment:%s" (file-name-nondirectory to)))
+((string-match-p (format "^file.*:%s\\'" from) (match-string 1))
+ (format "file:%s" to)))
+   nil nil nil 1

Diff finished.  Tue Mar 22 12:26:56 2022

All this patch does is to remove the directory name from the
=attachment:file.ext= -- given that the path is calculated by org-attach
--, and use the group 1 of the match string (as well as updating the use
of an obsolete variable), which corresponds to the actual link portion,
leaving the description unchanged.

Cordially,

-- 
João Pedro de A. Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Move or rename a file in a link

2022-03-18 Thread João Pedro de Amorim Paula
On 10 March 2022 14:58, Juan Manuel Macías  wrote:

> Hi João, Thanks for your comment.

Hello, Juan! I apologize for the delay on responding, I had some issues
with my e-mail account lately.

> Regarding attachments, do you mean org attachments or email attachments?
> Could you give an example of a use case?

I mean org attachments. I use org-attach extensively to store documents
with notes. So I'd have a heading like so

* Documents
:PROPERTIES:
:DIR: data/docs/
:END:

- [[Registration][attachment:registration.pdf]] :: My registration.

And say I'd like to rename the file. I would need to rename it inside
data/docs and I would also need to edit the link, so I would like to
have a way to do it automatically. I just got a computer back so I will
be trying to adapt what you did to work with org-attach, but if you
figure out a way to do it as well, please, let me know.

Regards,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Move or rename a file in a link

2022-03-09 Thread João Pedro de Amorim Paula
On 05 March 2022 19:58, Juan Manuel Macías  wrote:

Hello Juan!

> Hi all,
>
> I have written this simple function to move or rename a destination file
> in an external link at point. I share it here in case it is useful to
> someone.
>
> Best regards,
>
> Juan Manuel 
>
> #+begin_src emacs-lisp
> (defun my-org-replace-link-file (from to)
>   (save-excursion
> (goto-char (point-min))
> (while (re-search-forward org-bracket-link-regexp nil t)
>   (when (string-match-p from (match-string 1))
>   (replace-match (concat "[[file:" to "]]"))
>
> (defun my-org-rename-link-file-at-point ()
>   "Rename or move a file in an external link at point and
>   update the link path"
>   (interactive)
>   (let* ((curr-dir (abbreviate-file-name default-directory))
>(current-path (org-element-property :path (org-element-context)))
>(new-path (read-file-name "Rename file at point to: " current-path)))
> (rename-file current-path new-path)
> (message (concat "moved to: " new-path))
> (if (directory-name-p new-path)
>   (setq new-path (concat new-path (file-name-nondirectory current-path)))
>   (setq new-path new-path))
> (my-org-replace-link-file current-path
> (replace-regexp-in-string curr-dir "" new-path
>
> #+end_src
>

Thanks for sharing! It'd be great if it worked for attachments as well,
but that is a whole can of worms.

Cheers,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Unable to get current or via use-package

2022-02-18 Thread João Pedro de Amorim Paula
On 18 February 2022 18:32, João Pedro de Amorim Paula 
 wrote:

> I ended up not posting the link[1] I referred to in the first e-mail,

Welp, seems like I did it again... But no harm done this time, all the
necessary code was attached anyway :P

Forgetfully,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Unable to get current or via use-package

2022-02-18 Thread João Pedro de Amorim Paula
On 17 February 2022 16:00, "Loris Bennett"  wrote:

> What exactly would you like me to test?

I ended up not posting the link[1] I referred to in the first e-mail,
but since then I got back home and tested the functions provided there
seem to be doing what I expected. With it, I can force Emacs to download
a built-in package from ELPA and use it, instead of the built-in
version. I was afraid that I was only downloading it, but Emacs wasn't
actually loading it, but I couldn't test it because I have Emacs
28.0.91, which contains the latest versions of all the built-in packages
that are also in ELPA.

Given that, I have compiled Emacs 27 and ran it with the attached
init.el, and running M-x org-version tells me

Org mode version 9.5.2 (9.5.2-gfbff08 @ .../.emacs.d/elpa/org-9.5.2/)

It seems that calling my (require-package 'pkg 'force) is getting the
latest ELPA version available for built-in packages and using that
programatically, without having to use the Package List interface.

Regards,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)



init.el
Description: application/emacs-lisp


Re: Unable to get current or via use-package

2022-02-10 Thread João Pedro de Amorim Paula
On 10 February 2022 17:57, João Pedro de Amorim Paula 
 wrote:

> I had a similar issue in the recent past and was able to come up with a
> solution using the built-in package.el. Not sure how to make it work
> with use-package, but that at least seems to solve the issue of it not
> installing the ELPA version.

Forgot to add the link to my previous email, oops!

https://lists.gnu.org/archive/html/emacs-orgmode/2022-02/msg00062.html

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Unable to get current or via use-package

2022-02-10 Thread João Pedro de Amorim Paula
On 09 February 2022 16:51, "Loris Bennett"  wrote:

> Thanks, that did the trick.  I was hoping that when I use the same
> init.el on a different machine I wouldn't have to remember anything and
> use-package would automatically install the latest version.  Seemingly
> not :-/

I had a similar issue in the recent past and was able to come up with a
solution using the built-in package.el. Not sure how to make it work
with use-package, but that at least seems to solve the issue of it not
installing the ELPA version.

Not really sure if the version installed is the one that Emacs actually
uses, though, I am on Emacs 28.0.91 and all of the built-in packages I
have are the same version as their ELPA counterpart, so Emacs seems to be
prioritizing the built-in version. It could be that this is only the
case because they're both the same version; and seem as I'm traveling
ATM I couldn't test it against Emacs 27, so it would be great if you
could check it.

Cheers,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Suggestion: convert dispatchers to use transient

2022-02-05 Thread João Pedro de Amorim Paula
On 05 February 2022 18:49, Samuel Wales  wrote:

> jus want to state the obvious here in case it is useful [but everybody
> probbly lready knows] --- not everybody uses packages or maybe trusts
> them has internet etc.

Indeed! What I posted assumes using packages, but they also work with
any package-desc object. So, if you download it locally and build the
package-desc for it it should also work, just have to put it in place of
the assq:

>> (let ((pkg-desc (assq 'org package-archive-contents)))
   
>>   (package-install pkg-desc))

Although Tim was referring to packages on ELPA that are also built-in.

-- 
João Pedro de A. Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: Suggestion: convert dispatchers to use transient

2022-02-05 Thread João Pedro de Amorim Paula
On 04 February 2022 08:30, Tim Cross  wrote:

> I'm assuming it is, but I have to admit I'm still not 100% clear on
> how Emacs handles the situation where you use a library that is both
> built-in and available in ELPA. Does Emacs use the latest version
> available or does it use the built-in version until you explicitly
> select the ELPA versions?

Welp, I happened to ponder the same question after trying to implement a
function to install packages that are not installed already (I'm not
using any helper configuration such as use-package, which would already
handle this). From what I gathered empirically, it appears that if
something is built-in, Emacs' package.el won't try to install -- it
checks with package-installed-p on any call to package-install, which
checks if the package is built-in with package-built-in-p as a fallback
on cond --, but you can force installation from the archives by passing
a package description object (defined as package-desc on package.el)
instead of a symbol

(let ((pkg-desc (assq 'org package-archive-contents)))
  (package-install pkg-desc))

and Emacs seems to be loading the newest version when it is a dependency
of something else. Though I'm not really sure, as most of the packages I
have from ELPA have the same version as the ones built-in on Emacs
28.0.91. I'll try and install Emacs 27 to check this out.

In the mean time, I guess this would be a good opportunity to share a
couple of functions I have with the purpose of installing packages.

(defun pkg-description (package)
  "Return the description for PACKAGE.
If PACKAGE is installed, the will be present on `package-alist',
otherwise look for it in `package-archive-contents'."
  (or (cadr (assoc package package-alist))
  (cadr (assoc package package-archive-contents

(defun pkg-ensure-archive (package)
  "Install PACKAGE from the archives, if not already installed."
  (when-let ((pkg-desc (pkg-description package)))
(unless (package-installed-p pkg-desc)
  (package-install-from-archive pkg-desc

(defun require-package (package  force)
  "Ensure that PACKAGE is installed.
If FORCE is non-nil, force installation regardless if PACKAGE is
built-in or not.

First, use `package-installed-p' to check if PACKAGE was
installed via the Emacs package manager, otherwise, try to
`require' PACKAGE; this ensures that we don't require PACKAGE if
it was installed using the package manager. If both of those
fail, run `package-refresh-contents' and install PACKAGE."
  (unless (and (not force)
   (or (package-installed-p package)
   (require package nil 'no-error)))
(unless (assoc package package-archive-contents)
  (package-refresh-contents))
(if force
(pkg-ensure-archive package)
  (package-install package

On the last one, the main function that I use, if FORCE is non-nil it
will download and install the package from the archives even if it is
built-in.

Best regards,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


Re: [PATCH] Add support for $…$ latex fragments followed by a dash

2022-02-01 Thread João Pedro de Amorim Paula
On 01 February 2022 22:00, Rudolf Adamkovič  wrote:

> Me, I cannot use any of these "pretty" features because, simply put,
> they break plain text.  For example, they cause misaligned tables and
> make the text overflow the fill column, which I keep at 72 columns.

I know that this is a bit divergent from the original subject -- and
also keep in mind that this shouldn't be considered a solution to the
problem, given that it should be considered for all users with different
fonts --, but there are fonts that enforce Unicode (all characters, from
what I understand, Unicode included) characters to be exactly 1 unit
width, i.e. Unicode characters are the same widths as other characters.
At least I can guarantee that any of the Term (all characters are the
same length, but has ligatures) or Fixed (same as Term but no ligatures)
for Iosekva [1] have this given property.

[1] https://typeof.net/Iosevka/

Best regards,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)