masasam / emacs-easy-hugo

Emacs major mode for managing hugo

Home Page:https://gohugo.io/tools/editors/#emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using `require` is better to check `helm-ag` or `counsel` installed or not

SuzumiyaAoba opened this issue · comments

Now using package-installed-p but it can support users who install packages via package.el.

emacs-easy-hugo/easy-hugo.el

Lines 1163 to 1167 in 3b0516c

(if (package-installed-p 'counsel)
(counsel-ag nil (expand-file-name easy-hugo-postdir easy-hugo-basedir))
(if (package-installed-p 'helm-ag)
(helm-ag (expand-file-name easy-hugo-postdir easy-hugo-basedir))
(error "'counsel' or 'helm-ag' is not installed")))))

This doesn't support those who use Cask, el-get, etc.
Is it better to use require instead of package-installed-p?

(defun easy-hugo-ag ()
  "Search for blog article with counsel-ag or helm-ag."
  (interactive)
  (easy-hugo-with-env
   (if (require 'counsel nil t)
       (counsel-ag nil (expand-file-name easy-hugo-postdir easy-hugo-basedir))
     (if (require 'helm-ag nil t)
	 (helm-ag (expand-file-name easy-hugo-postdir easy-hugo-basedir))
         (error "'counsel' or 'helm-ag' is not installed")))))

Hi @SuzumiyaAoba .
Thank you for comment.

This doesn't support those who use Cask, el-get, etc.
Is it better to use require instead of package-installed-p?

You're right.
I 've fixed it at e0bbe40.
Thank you for your advice.

Thanks for your swift response.

It works for me, but new problem appears.
If I installed both counsel and helm-ag then it is forced to use counsel-ag
(I mainly use helm-ag, but counsel is also installed because some packages seem like depending on counsel).
So this package should provide the option of using helm-ag or counsel.

Hi @SuzumiyaAoba .
Make helm-ag and counsel-ag selectable at 8bf48b9 .

You can use helm-ag by writing the following to .emacs or init.el

(setq easy-hugo-helm-ag t)

Thanks for your work!

This package is more useful 🎉