Skip to content
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

feat(indicators): add cited #763

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ By default, it includes plain text indicators for, each of which indicates the p
- notes
- library files
- links
- cited (for references cited in the current buffer)

For other indicators, see the [[https://github.com/emacs-citar/citar/wiki/Indicators][wiki]].

Expand Down
25 changes: 24 additions & 1 deletion citar.el
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,19 @@ in some cases when using icons.")
:function #'citar-has-notes
:tag "has:notes"))

(defvar citar-indicator-cited
(citar-indicator-create
:symbol "C"
:function #'citar-is-cited
:tag "is:cited"))

;; Indicator config

(defvar citar-indicators
(list citar-indicator-links
citar-indicator-files
citar-indicator-notes))
citar-indicator-notes
citar-indicator-cited))

(defcustom citar-symbols
`((file . ("F" . " "))
Expand Down Expand Up @@ -880,6 +887,15 @@ visible in the completion UI."
(if matchtagp sym emptysym)
padding))
(pos (length str)))
;; See https://github.com/emacs-citar/citar/issues/764 for explanation of what this code is doing.
;;
;; We say that the last character of the padding should be replaced by a space which stretches to the
;; position we want to.
;;
;; So for example if the icon has string width 1 but occupies 0.9 the space will stretch to occupy 1.1
;; and if the icon occupies 1.5 it will shrink to occupy 0.5.
;;
;; Emacs 29 has `vtable', which we might use here in the future as well.
(put-text-property (- pos 1) pos 'display
(cons 'space
(list :align-to (string-width str)))
Expand Down Expand Up @@ -1114,6 +1130,13 @@ nil, return nil."
(push (format urlformat fieldvalue) keylinks))))
(nreverse keylinks)))))))

(defun citar-is-cited ()
"Return function to check if reference is cited in buffer."
(let ((iscited
(citar--major-mode-function 'list-keys #'ignore)))
(lambda (citekey)
(member citekey iscited))))

(defun citar-has-files ()
"Return predicate testing whether entry has associated files.

Expand Down