From ca04f69c101cff4fd6e71a4c1642e3a169a0057b Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Fri, 7 Apr 2017 22:09:04 -0400 Subject: [PATCH] Make `yas-about' more informative * yasnippet.el (yas--loaddir): New constant. (yas-installed-snippets-dir): Use it to compute value. (yas-about): Get version from git or `package' if available. --- yasnippet.el | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index 47b8ff5..9934b4d 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -152,10 +152,13 @@ :prefix "yas-" :group 'editing) +(defconst yas--loaddir + (file-name-directory (or load-file-name buffer-file-name)) + "Directory that yasnippet was loaded from.") + (defvar yas-installed-snippets-dir nil) (setq yas-installed-snippets-dir - (when load-file-name - (expand-file-name "snippets" (file-name-directory load-file-name)))) + (expand-file-name "snippets" yas--loaddir)) (defconst yas--default-user-snippets-dir (expand-file-name "snippets" user-emacs-directory)) @@ -1977,9 +1980,21 @@ This works by stubbing a few functions, then calling (defun yas-about () (interactive) - (message (concat "yasnippet (version " - yas--version - ") -- pluskid/joaotavora/npostavs"))) + (message "yasnippet (version %s) -- pluskid/joaotavora/npostavs" + (or (ignore-errors (car (let ((default-directory yas--loaddir)) + (process-lines "git" "describe" + "--tags" "--dirty")))) + (when (and (featurep 'package) (fboundp 'package-desc-version)) + (ignore-errors + (let* ((yas-pkg (cdr (assq 'yasnippet package-alist))) + (version (package-version-join + (package-desc-version (car yas-pkg))))) + ;; Special case for MELPA's bogus version numbers. + (if (string-match "\\`20..[01][0-9][0-3][0-9][.][0-9]\\{3,4\\}\\'" + version) + (concat yas--version "-snapshot" version) + version)))) + yas--version))) ;;; Apropos snippet menu: