From 093ffa5fbf7143f4668bb0a3dc9659a5cc836e12 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 17 Jun 2023 17:20:29 +1000 Subject: Moving things one level deeper To ease gnu stow usage. Now we can do stow -t ~ emacs --- .emacs.d/lisp/my/my-semantic-scholar.el | 100 -------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 .emacs.d/lisp/my/my-semantic-scholar.el (limited to '.emacs.d/lisp/my/my-semantic-scholar.el') 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 -;; 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 . - -;;; 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 -- cgit v1.2.3