-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query affixes after adding key #607
Comments
Is it possible? Sure. Is it wise? IDK. I suspect the UX may get tricky. And one can just add them directly to the buffer now. Finally, there are other higher priorities ATM, including #591. Also, of note, for another approach to entering keys etc, see: https://github.com/mclear-tools/citar-capf For some users, that may work better. Note, though: I haven't gotten that working yet with Doom. |
Looks interesting, but no success with it on Doom here either... |
See here for someone experimenting with this, though he's advising https://kristofferbalintona.me/posts/202206141852/#advising-citar-org-update-pre-suffix This led me to wonder: It could be one is prompted only when inserting a single We could also add a little function for this to include in the embark |
@bdarcus Hello, I'm' the author of the article you linked. I happened to return and update my citar config today and decided to redo that override advice for I'm not too familiar with the internals of citar and the org-element API, but I cobbled together something that works for my use case. I defined a new Code;; Minor customizations to `citar-org--update-prefix-suffix'; just changed
;; prompts
(defun kb/c itar-org--update-prefix-suffix ()
"Change the pre/suffix text of the reference at point."
(let* ((ref (org-element-context))
(key (org-element-property :key ref))
(pre (string-trim-right
(read-string
(concat "Prefix for "
(propertize (concat key ": ") 'face 'mode-line-emphasis))
(org-element-property :prefix ref))))
(post (string-trim-left
(read-string
(concat "Suffix for "
(propertize (concat key ": ") 'face 'mode-line-emphasis))
(org-element-property :suffix ref))))
(v1 (org-element-property :begin ref))
(v2 (org-element-property :end ref)))
;; Change post to automatically have one space prior to any user-inputted
;; suffix
(setq post (concat (if (length> post 0) " " "") post))
(cl--set-buffer-substring v1 v2
(org-element-interpret-data
`(citation-reference
(:key ,key :prefix ,pre :suffix ,post))))))
;; Gave `kb/citar-org-update-prefix-suffix' the ability to set the
;; pre/suffixes for all references in reference
(defun kb/citar-org-update-prefix-suffix (&optional arg)
"Change the pre/suffix text of the reference at point.
If given ARG, change the prefix and suffix for every reference in
the citation at point."
(interactive "P")
;; Enable `typo' typographic character cycling in minibuffer. Particularly
;; useful in adding en- and em-dashes in citation suffixes (e.g. for page
;; ranges)
(when (featurep 'typo)
(add-hook 'minibuffer-mode-hook 'typo-mode)) ; Enable dashes
(save-excursion
(let* ((citation (or (citar-org-citation-at-point)
(error "Not on a citation reference")))
(refs (if (or arg (not (car (citar-org-key-at-point))))
(car citation)
(list (car (citar-org-key-at-point)))))
(beg (cadr citation)))
(dolist (ref refs)
(goto-char beg)
(re-search-forward ref (cddr (citar-org-citation-at-point)))
(setq beg (point))
(kb/citar-org--update-prefix-suffix))))
;; Remove hook if it was added earlier
(remove-hook 'minibuffer-mode-hook 'typo-mode))
(advice-add 'citar-org-update-pre-suffix :override #'kb/citar-org-update-prefix-suffix) It does the following:
There are several other personal customizations in the code I pasted, but this shows that this functionality is easily possible now. Here, I chose to rely on Let me know what you think. P.S. My code also resolves #606 since it was a simple matter of processing the prompted strings prior to inserting them into the buffer. |
I'll take a closer look later (or if you want to prepare a PR, at that), but in the meantime, yes, this sounds like something worth merging. And on:
I believe in the org module we only rely on |
You're right. Initially, I used regexp because I wasn't very familiar with the current I went back and changed my code to use org-element API rather than regexps. I made a pull request just now. Hope this helps. |
* Add ability to update affixes in multiple references in a citation. * Fix formatting (mostly whitespace) issues. Closes: #606, #607 --------- Co-authored-by: Kristoffer Balintona <[email protected]>
I think we've discussed that before, but would it be possible to prompt for affixes after selecting a key? Maybe in a loop so users can select multiple keys, add affixes for each until they are finished?
The text was updated successfully, but these errors were encountered: