[瞎折腾]给quelpa折腾个定义新源

源起

好多包无melpa源的包还是得git下来,但只用git submodule对于个人来说有些麻烦了,而对于github,在国内比较折腾,而有国内有两个可用的镜像:

研究了下quelpa,发现git源是焊死的,虽然可以用url代替,但总觉得不太舒服。

更改函数

因为:feacher指定源的时候是直接跳到函数的,所以可以直接重新定义函数quelpa-build--checkout-github来达到修正的目的。

(defun quelpa-build--checkout-github (name config dir)
  "Check package NAME with config CONFIG out of github into DIR."
  (let ((url (format "https://github.com.cnpm.org/%s.git" (plist-get config :repo))))
    (quelpa-build--checkout-git name (plist-put (copy-sequence config) :url url) dir)))

但自更新和melpa的更新都还是默认的,那我外边也把变量焊死

(defconst quelpa-melpa-repo-url custom/melpa-repo-url)
;; 安装的时候
(unless (package-installed-p 'quelpa)
  (with-temp-buffer
    (url-insert-file-contents custom/quelpa-el-url)
    (eval-buffer)
    ;; redef

  (defun quelpa-build--checkout-github (name config dir)
    "Check package NAME with config CONFIG out of github into DIR."
    (let ((url (format "https://github.com.cnpm.org/%s.git" (plist-get config :repo))))
      (quelpa-build--checkout-git name (plist-put (copy-sequence config) :url url) dir)))

    (quelpa-self-upgrade)))

定义宏

而要整个新的源又有些麻烦,直接定义个宏:

(defmacro utils/quelpa-git-https-sources--set (source-name source-url)
  "Add the source or modify default source."
  `(progn
     (defun ,(intern (format "quelpa-build--checkout-%s" source-name)) (name config dir)
     (let ((url (format "https://%s/%s.git" ,source-url (plist-get config :repo))))
       (quelpa-build--checkout-git name (plist-put (copy-sequence config) :url url) dir)))))

;; 这下可以很快添加源了
(utils/quelpa-git-https-sources--set "github" custom/github-com-cnpmjs-org)
(utils/quelpa-git-https-sources--set "gitee" "gitee.com")

把宏写在安装quelpa的前面,就可以简化代码了:

(unless (package-installed-p 'quelpa)
  (with-temp-buffer
    (url-insert-file-contents custom/quelpa-el-url)
    (eval-buffer)
    ;; redef
    (utils/quelpa-git-https-sources--set "github" custom/github-com-cnpmjs-org)
    (quelpa-self-upgrade)))

结束

折腾半天就搞了这个,发出来大家乐呵乐呵 :joy:

3 个赞
git config --global url."https://hub.fastgit.xyz/".insteadOf "https://github.com/"
git config protocol.https.allow always

我用的这个