From 0eb926c0cfcecc6138fecc00862c7737e3035a86 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sun, 26 Nov 2023 16:30:38 +0100 Subject: [PATCH] update tldr Signed-off-by: Andreas Gerler --- elpa/tldr-20191006.1059/tldr-autoloads.el | 31 ---- elpa/tldr-20191006.1059/tldr-pkg.el | 2 - elpa/tldr-20230301.136/tldr-autoloads.el | 37 +++++ elpa/tldr-20230301.136/tldr-pkg.el | 14 ++ .../tldr.el | 133 ++++++++++++------ 5 files changed, 139 insertions(+), 78 deletions(-) delete mode 100644 elpa/tldr-20191006.1059/tldr-autoloads.el delete mode 100644 elpa/tldr-20191006.1059/tldr-pkg.el create mode 100644 elpa/tldr-20230301.136/tldr-autoloads.el create mode 100644 elpa/tldr-20230301.136/tldr-pkg.el rename elpa/{tldr-20191006.1059 => tldr-20230301.136}/tldr.el (71%) diff --git a/elpa/tldr-20191006.1059/tldr-autoloads.el b/elpa/tldr-20191006.1059/tldr-autoloads.el deleted file mode 100644 index 2d0ce643..00000000 --- a/elpa/tldr-20191006.1059/tldr-autoloads.el +++ /dev/null @@ -1,31 +0,0 @@ -;;; tldr-autoloads.el --- automatically extracted autoloads -;; -;;; Code: -(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path)))) - -;;;### (autoloads nil "tldr" "tldr.el" (23994 46377 473082 731000)) -;;; Generated autoloads from tldr.el - -(autoload 'tldr-update-docs "tldr" "\ -Get or update tldr docs from source. - -\(fn)" t nil) - -(autoload 'tldr "tldr" "\ -Lookup tldr docs. - -\(fn &optional CMD)" t nil) - -(autoload 'helm-tldr "tldr" "\ -Helm interface for `tldr'. - -\(fn)" t nil) - -;;;*** - -;; Local Variables: -;; version-control: never -;; no-byte-compile: t -;; no-update-autoloads: t -;; End: -;;; tldr-autoloads.el ends here diff --git a/elpa/tldr-20191006.1059/tldr-pkg.el b/elpa/tldr-20191006.1059/tldr-pkg.el deleted file mode 100644 index 0f83d5f3..00000000 --- a/elpa/tldr-20191006.1059/tldr-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; -*- no-byte-compile: t -*- -(define-package "tldr" "20191006.1059" "tldr client for Emacs" '((emacs "24.3") (request "0.3.0")) :commit "b7f3e3e2171eab5707a42641f4470b69777feaea" :keywords '("tools" "docs") :authors '(("Ono Hiroko" . "azazabc123@gmail.com")) :maintainer '("Ono Hiroko" . "azazabc123@gmail.com") :url "https://github.com/kuanyui/tldr.el") diff --git a/elpa/tldr-20230301.136/tldr-autoloads.el b/elpa/tldr-20230301.136/tldr-autoloads.el new file mode 100644 index 00000000..4db8e5a8 --- /dev/null +++ b/elpa/tldr-20230301.136/tldr-autoloads.el @@ -0,0 +1,37 @@ +;;; tldr-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- +;; +;;; Code: + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + + +;;;### (autoloads nil "tldr" "tldr.el" (0 0 0 0)) +;;; Generated autoloads from tldr.el + +(autoload 'tldr-update-docs "tldr" "\ +Get or update the TLDR docs from source." t nil) + +(autoload 'tldr "tldr" "\ +Lookup TLDR docs. + +\(fn &optional CMD)" t nil) + +(autoload 'helm-tldr "tldr" "\ +Helm interface for `tldr'." t nil) + +(register-definition-prefixes "tldr" '("tldr-")) + +;;;*** + +;;;### (autoloads nil nil ("tldr-pkg.el") (0 0 0 0)) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; tldr-autoloads.el ends here diff --git a/elpa/tldr-20230301.136/tldr-pkg.el b/elpa/tldr-20230301.136/tldr-pkg.el new file mode 100644 index 00000000..0870ac90 --- /dev/null +++ b/elpa/tldr-20230301.136/tldr-pkg.el @@ -0,0 +1,14 @@ +(define-package "tldr" "20230301.136" "tldr client for Emacs" + '((emacs "24.3")) + :commit "1b09d2032491d3904bd7ee9bf5ba7c7503db6593" :authors + '(("Ono Hiroko" . "azazabc123@gmail.com")) + :maintainers + '(("Ono Hiroko" . "azazabc123@gmail.com")) + :maintainer + '("Ono Hiroko" . "azazabc123@gmail.com") + :keywords + '("tools" "docs") + :url "https://github.com/kuanyui/tldr.el") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/elpa/tldr-20191006.1059/tldr.el b/elpa/tldr-20230301.136/tldr.el similarity index 71% rename from elpa/tldr-20191006.1059/tldr.el rename to elpa/tldr-20230301.136/tldr.el index d727cd79..0ed5362b 100644 --- a/elpa/tldr-20191006.1059/tldr.el +++ b/elpa/tldr-20230301.136/tldr.el @@ -2,8 +2,7 @@ ;; Author: Ono Hiroko ;; Keywords: tools, docs -;; Package-Version: 20191006.1059 -;; Package-Requires: ((emacs "24.3") (request "0.3.0")) +;; Package-Requires: ((emacs "24.3")) ;; X-URL: https://github.com/kuanyui/tldr.el ;; Version: {{VERSION}} @@ -34,10 +33,9 @@ (require 'url) (require 'cl-lib) -(require 'request) (defgroup tldr nil - "tldr client for Emacs" + "An Emacs client for the TLDR community man pages." :prefix "tldr-" :link '(url-link "http://github.com/kuanyui/tldr.el") :group 'help) @@ -48,21 +46,28 @@ :group 'tldr :type 'string) +(defcustom tldr-enable-annotations t + "Add description of each command in the *Completions* buffer." + :group 'tldr + :type 'boolean) + (defcustom tldr-use-word-at-point nil - "Use the word at point as the initial search term when selecting a command" + "Use the word at point as the initial search term when +selecting a command." :group 'tldr :type 'boolean) (defcustom tldr-saved-zip-path (concat temporary-file-directory "tldr-source.zip") - "The temporary location for downloading zip" + "The temporary location for downloading the zipped TLDR +source." :group 'tldr :type 'string) (defcustom tldr-source-zip-url - "https://github.com/tldr-pages/tldr/archive/master.zip" - "Zip URL on GitHub." + "https://github.com/tldr-pages/tldr/archive/refs/heads/main.zip" + "The location of the zipped TLDR source on GitHub." :group 'tldr :type 'string) @@ -73,12 +78,18 @@ '("common" "osx")) (t '("common"))) - "List of enabled tldr categories." + "A list of the enabled TLDR categories." :group 'tldr :type '(repeat string)) ; [HELP] I don't know how to make checkbox for a string list +(defcustom tldr-locales + nil + "Priority list of locales to display tldr pages in." + :group 'tldr + :type '(repeat string)) + (define-derived-mode tldr-mode help-mode "tldr" - "Lookup tldr in Emacs" + "Lookup TLDR man pages from within in Emacs." (set (make-local-variable 'buffer-read-only) t)) @@ -134,38 +145,29 @@ "" :group 'tldr) +(defvar tldr-length-of-longest-command-name nil + "Length of the longest command name.") ;;;###autoload (defun tldr-update-docs () - "Get or update tldr docs from source." + "Get or update the TLDR docs from source." (interactive) (if (tldr--check-unzip) (progn (if (file-exists-p tldr-directory-path) (delete-directory tldr-directory-path 'recursive 'no-trash)) - (tldr-request-data tldr-source-zip-url tldr-saved-zip-path) + (if (file-exists-p tldr-saved-zip-path) + (delete-file tldr-saved-zip-path 'no-trash)) + (url-copy-file tldr-source-zip-url tldr-saved-zip-path) (shell-command-to-string (format "unzip -d %s %s" (file-truename user-emacs-directory) tldr-saved-zip-path)) (delete-file tldr-saved-zip-path) - (shell-command-to-string (format "mv '%s' '%s'" (concat (file-truename user-emacs-directory) "tldr-master") tldr-directory-path)) - (message "Now tldr docs is updated!")))) - - -(defun tldr-request-data (url file) - "Resuest data from URL and save file at the location of FILE." - (request - url - :parser 'buffer-string - :success - (cl-function (lambda (&key data &allow-other-keys) - (when data - (with-temp-buffer (get-buffer-create "*request data*") - (erase-buffer) - (insert data) - (write-file file) - (kill-buffer "*request data*"))))) - :error - (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) - (message "Got error: %S" error-thrown))))) + (if (member system-type '(windows-nt ms-dos)) + (shell-command-to-string (format "move \"%s\" \"%s\"" + (concat (file-truename user-emacs-directory) "tldr-main") + (directory-file-name tldr-directory-path))) + (shell-command-to-string (format "mv '%s' '%s'" (concat (file-truename user-emacs-directory) "tldr-main") tldr-directory-path))) + (message "The TLDR docs are up to date!")))) + (defun tldr-get-commands-list () "For `completing-read'" @@ -179,14 +181,43 @@ tldr-directory-path))) tldr-enabled-categories)))) +(defun tldr-get-locales () + "Return a priority list of locales as specified by +`tldr-locales' and the LANG and LANGUAGE environment variables." + (cond + (tldr-locales tldr-locales) + ((getenv "LANG") (list (getenv "LANG"))) + ((getenv "LANGUAGE") (split-string (getenv "LANGUAGE") ":")))) + +(defun tldr-page-exists-p (command system &optional locale) + "Return the file path of the tldr page specified by COMMAND, +SYSTEM and LOCALE. Return nil if such a page is not found. If +optional argument LOCALE is unspecified, return the file path of +the default English language page." + (cl-some (lambda (locale-extension) + (let ((filename + (expand-file-name + (convert-standard-filename + (format "pages%s/%s/%s.md" + locale-extension system command)) + tldr-directory-path))) + (and (file-exists-p filename) + filename))) + (if locale + (let ((language (when (string-match "^\\([^_]*\\)" locale) + (match-string 1 locale))) + (territory (when (string-match "^[^_]*_\\([^.]*\\)" locale) + (match-string 1 locale)))) + (list (format ".%s_%s" language territory) + (format ".%s" language))) + (list "")))) + (defun tldr-get-file-path-from-command-name (command) - (cl-find-if #'file-exists-p - (mapcar (lambda (system) - (expand-file-name - (convert-standard-filename - (format "pages/%s/%s.md" system command)) - tldr-directory-path)) - tldr-enabled-categories))) + (cl-some (lambda (system) + (or (cl-some (apply-partially #'tldr-page-exists-p command system) + (tldr-get-locales)) + (tldr-page-exists-p command system))) + tldr-enabled-categories)) (defun tldr-render-markdown (command) (let* ((file-path (tldr-get-file-path-from-command-name command)) @@ -209,7 +240,7 @@ (setq line (propertize (substring line 1 -1) 'face 'tldr-code-block)) ;; Add command face (setq line (replace-regexp-in-string - (concat "^" command) + (concat "^" (regexp-quote command)) (propertize command 'face 'tldr-command-itself) line 'fixedcase)) ;; Strip {{}} and add command argument face @@ -225,20 +256,32 @@ t (progn (message "unzip not found. Please install and run `tldr-update-docs' again.") nil))) +(defun tldr-completion-annotation(command) + "Add description for command COMMAND in the *Completions* buffer." + (when-let ((file-path (and tldr-enable-annotations (tldr-get-file-path-from-command-name command)))) + (with-temp-buffer + (insert-file-contents file-path) + (and (search-forward "> " (point-max) t 1) + (concat (make-string (- tldr-length-of-longest-command-name (length command)) ? ) + " -- " + (buffer-substring-no-properties (point) (line-end-position))))))) + ;;;###autoload (defun tldr (&optional cmd) - "Lookup tldr docs." + "Lookup TLDR docs." (interactive) (if (not (file-exists-p tldr-directory-path)) (if (tldr--check-unzip) (progn - (message "This is the first time using. -Please wait a minute for downloading latest tldr docs...") + (message "This is the first time you have run TLDR. +Please wait while the latest TLDR docs are downloaded...") (sit-for 3) (tldr-update-docs) (tldr))) - (let ((command (or cmd - (completing-read "tldr: " (tldr-get-commands-list) nil t + (setq tldr-length-of-longest-command-name (apply #'max (mapcar #'length (tldr-get-commands-list)))) + (let* ((completion-extra-properties '(:annotation-function tldr-completion-annotation)) + (command (or cmd + (completing-read "TLDR: " (tldr-get-commands-list) nil t (when tldr-use-word-at-point (current-word)))))) (if (string= "" command) (message "No input, canceled.") -- 2.47.3