al-magit-popup.el 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ;;; al-magit-popup.el --- Additional functionality for magit-popup library
  2. ;; Copyright © 2016, 2018 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'magit-popup)
  17. ;; This "previous popup" functionality is hardcoded in
  18. ;; 'magit-invoke-popup-action' to handle "q" key, but I want to bind it
  19. ;; to another key. I didn't make a pull request to add
  20. ;; 'magit-popup-previous-or-quit' and to bind it to "q" in
  21. ;; 'magit-popup-mode-map' because it would be undesired, if I understood
  22. ;; it right from the commit message of
  23. ;; <https://github.com/magit/magit/commit/2ef07e3aa01b19b68e348ee4c4ed9e3428ef4e1e>.
  24. ;;;###autoload
  25. (defun al/magit-popup-previous-or-quit ()
  26. "Quit the current popup and return to the previous one if possible."
  27. (interactive)
  28. (magit-popup-quit)
  29. (when magit-previous-popup
  30. (magit-popup-mode-setup magit-previous-popup nil)))
  31. ;; There is `magit-remove-popup-key' but no `magit-add-popup-key'.
  32. (defun al/magit-add-popup-key (popup type value)
  33. "In POPUP, add VALUE to TYPE property.
  34. POPUP is a popup command defined using `magit-define-popup'.
  35. TYPE is one of `:action', `:sequence-action', `:switch', or
  36. `:option'."
  37. (setq type (magit-popup-pluralize-type type))
  38. (let* ((plist (symbol-value popup))
  39. (alist (plist-get plist type)))
  40. (set popup (plist-put plist type
  41. (append alist (list value))))))
  42. (defun al/magit-add-popup-keys (popup type values)
  43. "In POPUP, add list of VALUES to TYPE property.
  44. See `al/magit-add-popup-key' for details."
  45. (dolist (value values)
  46. (al/magit-add-popup-key popup type value)))
  47. (provide 'al-magit-popup)
  48. ;;; al-magit-popup.el ends here