Git Product home page Git Product logo

Comments (7)

tmalsburg avatar tmalsburg commented on June 12, 2024 1

Nice!

My earlier code was unnecessarily complicated. The code below does the same in fewer words:

(advice-add 'bibtex-completion-candidates
            :filter-return 'reverse)

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 12, 2024

Helm-bibtex doesn't sort at all. The entries appear in the reverse order in which they are listed in the bib-file. I actually like this behavior. I add new entries at the end of the file and want them to show at the top in helm-bibtex because they are most relevant to my current work. Currently, the only way to affect the order is to sort your bib-file. I agree that it would be useful to able to configure sorting (and there is already an issue for that: #5) but I won't have time to implement that anytime soon. It shouldn't be too hard, though, and you might want to try it yourself.

from helm-bibtex.

jagrg avatar jagrg commented on June 12, 2024

You are right. It makes more sense to show recent entries on top. I'll use that instead.

from helm-bibtex.

rjww avatar rjww commented on June 12, 2024

You can un- or re-reverse the candidate order by advising the appropriate formatter function, intercepting the list of candidates passed from bibtex-completion-candidates. For example, if you're using Helm:

(defun -helm-bibtex--reverse-candidates (orig-fun &rest args)
  (setcar args (reverse (car args)))
  (apply orig-fun args))

(advice-add 'helm-bibtex-candidates-formatter
            :around #'-helm-bibtex--reverse-candidates)

I know this is an old (and closed) issue, but I'm putting this here in case anyone comes through looking for a solution. I assume some people are like me in keeping their .bib files sorted, e.g. to avoid crossref conflicts.

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 12, 2024

Thank you, @rjww. One thing to note is that this solution only reverses the list of top-500 entries, so the list of entries is going to start somewhere in the middle of your BibTeX file not at the beginning. The following code reverses the whole list:

(advice-add 'bibtex-completion-candidates
            :around (lambda (orig-fun &rest args)
                      (reverse (apply orig-fun args))))

from helm-bibtex.

jagrg avatar jagrg commented on June 12, 2024

Nice. We can also do it interactively.

(defun helm-bibtex-reverse-candidates (arg)
  (interactive "P")
  (with-selected-window (helm-window)
    (if arg
    (advice-remove 'bibtex-completion-candidates
               '(lambda (orig-fun &rest args)
              (reverse (apply orig-fun args))))
      (advice-add 'bibtex-completion-candidates
          :around (lambda (orig-fun &rest args)
                (reverse (apply orig-fun args)))))
    (helm-refresh)
    (helm-goto-line 1)))

(define-key helm-map (kbd "<f9>") 'helm-bibtex-reverse-candidates)

from helm-bibtex.

rjww avatar rjww commented on June 12, 2024

Thanks for the improvements guys!

from helm-bibtex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.