|
45 | 45 |
|
46 | 46 | ;;;###autoload |
47 | 47 | (defun citar-markdown-insert-citation (keys) |
48 | | - "Insert a pandoc-style citation consisting of KEYS." |
49 | | - (let* ((prenote (if citar-markdown-prompt-for-extra-arguments |
50 | | - (read-from-minibuffer "Prenote: "))) |
51 | | - (postnote (if citar-markdown-prompt-for-extra-arguments |
52 | | - (read-from-minibuffer "Postnote: "))) |
53 | | - (prenote (if (string= "" prenote) "" (concat prenote " "))) |
54 | | - (postnote (if (string= "" postnote) "" (concat ", " postnote)))) |
55 | | - (insert (format "[%s%s%s]" |
56 | | - prenote |
57 | | - (mapconcat (lambda (k) (concat "@" k)) keys "; ") |
58 | | - postnote)))) |
| 48 | + "Insert a pandoc-style citation consisting of KEYS. |
| 49 | +If the point is inside a citation, add new keys after the current |
| 50 | +key. If point is immediately after the opening \[, add new keys |
| 51 | +to the beginning of the citation." |
| 52 | + (let* ((citation (citar-markdown-citation-at-point)) |
| 53 | + (keys (if citation (seq-difference keys (car citation)) keys)) |
| 54 | + (keyconcat (mapconcat (lambda (k) (concat "@" k)) keys "; "))) |
| 55 | + (when keys |
| 56 | + (if (or (not citation) |
| 57 | + (= (point) (cadr citation)) |
| 58 | + (= (point) (cddr citation))) |
| 59 | + (let* ((prenote (when citar-markdown-prompt-for-extra-arguments |
| 60 | + (read-from-minibuffer "Prenote: "))) |
| 61 | + (postnote (when citar-markdown-prompt-for-extra-arguments |
| 62 | + (read-from-minibuffer "Postnote: "))) |
| 63 | + (prenote (if (string= "" prenote) "" (concat prenote " "))) |
| 64 | + (postnote (if (string= "" postnote) "" (concat ", " postnote)))) |
| 65 | + (insert (format "[%s%s%s]" prenote keyconcat postnote))) |
| 66 | + (if (= (point) (1+ (cadr citation))) |
| 67 | + (save-excursion (insert keyconcat "; ")) |
| 68 | + (skip-chars-forward "^;]" (cddr citation)) |
| 69 | + (insert "; " keyconcat)))))) |
59 | 70 |
|
60 | 71 | (defconst citar-markdown-citation-key-regexp |
61 | 72 | (concat "-?@" ; @ preceded by optional - |
|
0 commit comments