doomemacs/modules/tools/magit/autoload.el
Henrik Lissner bab530ea2e
Revert +hub flag, but disable magithub by default
Must be enabled on a per-project basis. You can change this behavior by
setting +magit-hub-enabled-by-default to non-nil (before magit is
loaded).

Magithub has been made opt-in because:

1. Magithub is imposing, asking the user for a token, especially for
   users who don't use github (much or at all), but may occasionally
   have a project with a github remote.
2. magithub is really slow on first load for medium-to-large repos.
3. It's really easy to enable it through the magithub popup (H C e).
   magithub.enabled is saved into the project's .git/config file, so the
   setting will persist.

Also added a docstring to +magit-hub-features
2018-06-01 11:13:37 +02:00

70 lines
2.3 KiB
EmacsLisp

;;; tools/magit/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +magit/quit (&optional _kill-buffer)
"Clean up magit buffers after quitting `magit-status'."
(interactive)
(let ((buffers (magit-mode-get-buffers)))
(magit-restore-window-configuration)
(mapc #'+magit--kill-buffer buffers)))
(defun +magit--kill-buffer (buf)
"TODO"
(when (and (bufferp buf) (buffer-live-p buf))
(let ((process (get-buffer-process buf)))
(if (not (processp process))
(kill-buffer buf)
(with-current-buffer buf
(if (process-live-p process)
(run-with-timer 5 nil #'+magit--kill-buffer buf)
(kill-process process)
(kill-buffer buf)))))))
(defvar +magit-clone-history nil
"History for `+magit/clone' prompt.")
;;;###autoload
(defun +magit/clone (url-or-repo dir)
"Delegates to `magit-clone' or `magithub-clone' depending on the repo url
format."
(interactive
(progn
(require 'magithub)
(let* ((user (ghubp-username))
(repo (read-from-minibuffer
"Clone repository (user/repo or url): "
(if user (concat user "/"))
nil nil '+magit-clone-history))
(name (car (last (split-string repo "/" t)))))
(list repo
(read-directory-name
"Destination: "
magithub-clone-default-directory
name nil name)))))
(require 'magithub)
(if (string-match "^\\([^/]+\\)/\\([^/]+\\)$" url-or-repo)
(let ((repo `((owner (login . ,(match-string 1 url-or-repo)))
(name . ,(match-string 2 url-or-repo)))))
(and (or (magithub-request
(ghubp-get-repos-owner-repo repo))
(let-alist repo
(user-error "Repository %s/%s does not exist"
.owner.login .name)))
(magithub-clone repo dir)))
(magit-clone url-or-repo dir)))
;;
;; Advice
;;
;;;###autoload
(defun +magit*hub-settings--format-magithub.enabled ()
"Change the setting to display 'false' as its default."
(magit--format-popup-variable:choices "magithub.enabled" '("true" "false") "false"))
;;;###autoload
(defun +magit*hub-enabled-p ()
"Disables magithub by default."
(magithub-settings--value-or "magithub.enabled" nil
#'magit-get-boolean))