Klimi's new dotfiles with stow.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

79 行
3.1 KiB

  1. ;;; use-package-jump.el --- Attempt to jump to a use-package declaration -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2012-2017 John Wiegley
  3. ;; Author: John Wiegley <johnw@newartisans.com>
  4. ;; Maintainer: John Wiegley <johnw@newartisans.com>
  5. ;; Created: 17 Jun 2012
  6. ;; Modified: 3 Dec 2017
  7. ;; Version: 1.0
  8. ;; Package-Requires: ((emacs "24.3") (use-package "2.4"))
  9. ;; Keywords: dotemacs startup speed config package
  10. ;; URL: https://github.com/jwiegley/use-package
  11. ;; This program is free software; you can redistribute it and/or
  12. ;; modify it under the terms of the GNU General Public License as
  13. ;; published by the Free Software Foundation; either version 3, or (at
  14. ;; your option) any later version.
  15. ;; This program is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. ;; General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  21. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. ;; Boston, MA 02111-1307, USA.
  23. ;;; Commentary:
  24. ;; Provides the command `M-x use-package-jump-to-package-form', however it
  25. ;; only works if the package being jumped to was required during
  26. ;; initialization. If it was delay-loaded, it will not work. Improvements are
  27. ;; needed.
  28. ;;; Code:
  29. (require 'use-package-core)
  30. (defun use-package-find-require (package)
  31. "Find file that required PACKAGE by searching `load-history'.
  32. Returns an absolute file path or nil if none is found."
  33. (catch 'suspect
  34. (dolist (filespec load-history)
  35. (dolist (entry (cdr filespec))
  36. (when (equal entry (cons 'require package))
  37. (throw 'suspect (car filespec)))))))
  38. ;;;###autoload
  39. (defun use-package-jump-to-package-form (package)
  40. "Attempt to find and jump to the `use-package' form that loaded
  41. PACKAGE. This will only find the form if that form actually
  42. required PACKAGE. If PACKAGE was previously required then this
  43. function will jump to the file that originally required PACKAGE
  44. instead."
  45. (interactive (list (completing-read "Package: " features)))
  46. (let* ((package (if (stringp package) (intern package) package))
  47. (requiring-file (use-package-find-require package))
  48. file location)
  49. (if (null requiring-file)
  50. (user-error "Can't find file requiring file; may have been autoloaded")
  51. (setq file (if (string= (file-name-extension requiring-file) "elc")
  52. (concat (file-name-sans-extension requiring-file) ".el")
  53. requiring-file))
  54. (when (file-exists-p file)
  55. (find-file-other-window file)
  56. (save-excursion
  57. (goto-char (point-min))
  58. (setq location
  59. (re-search-forward
  60. (format (eval use-package-form-regexp-eval) package) nil t)))
  61. (if (null location)
  62. (message "No use-package form found.")
  63. (goto-char location)
  64. (beginning-of-line))))))
  65. (provide 'use-package-jump)
  66. ;;; use-package-jump.el ends here