1

I’m trying to install git-gutter or git-gutter-fringe depending if I’m running in graphics mode or not. I have an if statement for that:

(if (display-graphic-p)
    (use-package git-gutter-fringe
      ;; package setup here)
  (use-package git-gutter
    ;; same package setup here))

I was trying to do it with

(use-package (if (display-graphic-p) git-gutter-fringe git-gutter)
  ;; package setup here)

or

(let ((package-name (if (display-graphic-p) "git-gutter-fringe" "git-gutter-fringe")))
  (use-package package-name
    ;; package setup here))

But none of these succeeds.

The final question is, is it possible to do what I want, or do I have to stay with my current config?

3
  • FWIW this question seems rather odd to me, and perhaps for anyone who tends to open both GUI and terminal Emacs clients at different times to the same long-running server. Even activating different libraries for different display types doesn't necessarily make sense to me (I might, over time, view any given buffer in multiple display types), let alone installing different libraries. You may (or may not) find it worth considering such scenarios, even if they don't apply to you currently.
    – phils
    Nov 8, 2016 at 0:03
  • p.s. If you can't figure out why someone might use both types, for me it's a matter of whether I'm connecting to the server locally (in which case the network is fast enough to use GUI clients), or remotely (in which case I've found that the performance benefits of using a terminal client far outweigh any other considerations).
    – phils
    Nov 8, 2016 at 0:06
  • The whole thing about installing is 100% true; the same thing almost can be said about activation; in this case however, the git-gutter-* packages author decided to use the same mode name for both; so, if I well understand it, he imposes this decision of using only one of these packages at the same time. Hence the 3rd code fragment in my answer. I suppose one could alias/change the mode name of the fringe version, and activate that - or the other - per window type.
    – VanLaser
    Nov 8, 2016 at 8:52

1 Answer 1

2

Your first try should work? I.e. something like this:

(if (display-graphic-p)
   (use-package git-gutter-fringe
     :ensure t
     :init (global-git-gutter-mode))
 (use-package git-gutter
  :ensure t
  :init (global-git-gutter-mode)))

For your 2nd try, since use-package is a macro, the if is not evaluated before the "call". This should evaluate it when needed:

(let ((package-name (if (display-graphic-p)
                        "git-gutter-fringe"
                      "git-gutter")))
  (eval `(use-package ,package-name
    :ensure t
    :init (global-git-gutter-mode))))

From my tests, the fringe version also installs git-gutter, so there may be other approaches to this. You could simply install both, and enable the right mode based on display-graphic-p. E.g., I'd use:

(use-package git-gutter                                                                                              
  :ensure t                                                                                                          
  :init                                                                                                              
  (when (display-graphic-p)                                                                                          
      (use-package git-gutter-fringe                                                                                 
        :ensure t))                                                                                                  
  (global-git-gutter-mode))   

For those who don't use git-gutter*, both packages use the same mode name, hence the similar code in both situations (only the package names are different).

I'm not a great lisper, so there may be other, smarter & shorter solutions out there.

1
  • 1
    Your let version is working fine, thank you! I don’t really like my current approach, or your third one because I want to use the same configuration for the two packages (I’m speaking about key bindings, color/icon configuration and such). Nov 8, 2016 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.