diff options
author | Yuchen Pei <id@ypei.org> | 2023-06-17 17:20:29 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-06-17 17:20:29 +1000 |
commit | 093ffa5fbf7143f4668bb0a3dc9659a5cc836e12 (patch) | |
tree | 1ed4e14b2a43b8e338f4ad6a04d969b99b9239be /.emacs.d/lisp/my/my-semantic-scholar.el | |
parent | abc686827ae38ee715d9eed1c5c29161c74127e6 (diff) |
Moving things one level deeper
To ease gnu stow usage. Now we can do
stow -t ~ emacs
Diffstat (limited to '.emacs.d/lisp/my/my-semantic-scholar.el')
-rw-r--r-- | .emacs.d/lisp/my/my-semantic-scholar.el | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/.emacs.d/lisp/my/my-semantic-scholar.el b/.emacs.d/lisp/my/my-semantic-scholar.el deleted file mode 100644 index 4b22390..0000000 --- a/.emacs.d/lisp/my/my-semantic-scholar.el +++ /dev/null @@ -1,100 +0,0 @@ -;;; my-semantic-scholar.el -- Semantic Scholar client -*- lexical-binding: t -*- - -;; Copyright (C) 2023 Free Software Foundation. - -;; Author: Yuchen Pei <id@ypei.org> -;; Package-Requires: ((emacs "28.2")) - -;; This file is part of dotfiles. - -;; dotfiles is free software: you can redistribute it and/or modify it under -;; the terms of the GNU Affero General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; dotfiles is distributed in the hope that it will be useful, but WITHOUT -;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General -;; Public License for more details. - -;; You should have received a copy of the GNU Affero General Public -;; License along with dotfiles. If not, see <https://www.gnu.org/licenses/>. - -;;; Commentary: - -;; Semantic Scholar client. - -;;; Code: - -(require 'my-utils) -(require 'my-scihub) - -(defvar my-semantic-scholar-host - "https://api.semanticscholar.org/graph/v1") -(defun my-semantic-scholar-fetch-papers-for-completion (query) - (with-current-buffer - (url-retrieve-synchronously - (format "%s/paper/search?query=%s" my-semantic-scholar-host query)) - (my-skip-http-header) - (mapcar - (lambda (entry) - (concat - (alist-get 'title entry) - (propertize - (concat " " - (alist-get 'paperId entry)) - 'invisible t))) - (alist-get 'data (json-read))))) - -(defun my-semantic-scholar-make-paper-alist (paper-info) - (list (cons "Authors" - (string-join - (mapcar (lambda (entry) (alist-get 'name entry)) - (alist-get 'authors paper-info)) - " and ")) - (cons "Title" (alist-get 'title paper-info)) - (cons "Published" - (number-to-string (alist-get 'year paper-info))) - (cons "Abstract" (my-clean-property-value - (alist-get 'abstract paper-info))) - (cons "Venue" (alist-get 'venue paper-info)) - (cons "arXiv" (alist-get - 'ArXiv (alist-get 'externalIds paper-info))) - (cons "DOI" (alist-get - 'DOI (alist-get 'externalIds paper-info))) - (cons "Semantic-scholar" (alist-get 'paperId paper-info)))) - -(defun my-semantic-scholar-lookup-paper () - "looks up a paper using semantic scholar api, prompts for selection and creates a org entry." - (interactive) - (let* ((query (read-string "Query: ")) - (selected (completing-read - "Select paper:" ;; '("a" "b") - (my-semantic-scholar-fetch-papers-for-completion query)))) - (with-current-buffer - (url-retrieve-synchronously - (format - "%s/paper/%s?fields=title,abstract,authors,venue,year,externalIds" - my-semantic-scholar-host - (progn (string-match "^.* \\(.*\\)$" selected) - (match-string 1 selected)))) - (my-skip-http-header) - (my-org-create-node (my-semantic-scholar-make-paper-alist (json-read))) - (my-org-attach-scihub)))) - -(defun my-semantic-scholar-lookup-doi () - "looks up a paper using semantic scholar api, prompts for selection and creates a org entry." - (interactive) - (let ((doi (read-string "DOI: "))) - (with-current-buffer - (url-retrieve-synchronously - (format - "%s/paper/%s?fields=title,abstract,authors,venue,year,externalIds" - my-semantic-scholar-host - doi)) - (my-skip-http-header) - (my-org-create-node (my-semantic-scholar-make-paper-alist (json-read))) - (my-org-attach-scihub)))) - -(provide 'my-semantic-scholar) -;;; my-semantic-scholar.el ends here |