hvesalai / emacs-sbt-mode

An emacs mode for interacting with scala sbt and projects
GNU General Public License v3.0
126 stars 38 forks source link

Subproject list can run out of space #166

Open nigredo-tori opened 3 years ago

nigredo-tori commented 3 years ago

See the first hydra line here: image

This makes sbt-hydra unusable in monorepository projects where there can be a lot of subprojects with lengthy names, which can't all fit on one line. Some kind of word wrapping is in order.

As a temporary workaround, I've replaced sbt-hydra:project-switcher:

(defun my/wrap-item-lines (seq max-width)
  "Split SEQ (a sequence of strings) into lines, attempting to keep each line's width below MAX-WIDTH"
  (flet ((step (acc item)
               ;; acc is '(<result string> <last line width>)
               (let* ((s (car acc))
                      (width (car (cdr acc)))
                      (new-width (+ width 1 (length item))))
                 (cond ((zerop width) (list item (length item)))
                       ((<= new-width max-width) (list (concat s " " item) new-width))
                       (t (list (concat s "\n" item) (length item)))))
               ))
    (car (-reduce-from 'step '("" 0) seq))))

(defun sbt-hydra:project-switcher (current-project project-names)
  (let* ((keys (mapcar 'char-to-string (number-sequence 65 (+ 65 (length project-names)))))
         (current-project-array (make-vector (length project-names) current-project))
         (project-items (cl-mapcar 'sbt-hydra:keys-and-projects current-project-array keys project-names) ))
    (my/wrap-item-lines project-items (frame-width))))

For some reason just adding a defun doesn't work, I had to directly patch sbt-mode-hydra.el.

The result is as follows:

image

By the way, it seems like the chosen triggers for subprojects start to overlap with other commands, which probably deserves its own issue.

VlachJosef commented 3 years ago

Another option how to resolve this is to use sbt-hydra:projects. It allows you to specify subset of projects you need the most so that they can fit on one line.

For example put this into .dir-locals.el file at the root of the sbt project:

((sbt-mode . ((sbt-hydra:projects . ("root" "blaze-client" "core" "docs" "website" "blaze-core" "blaze-server" "client" "circe" "dsl" "server" "tests" "twirl" "play-json" "examples" "laws")))))

Doing this also allows you to put projects in order of importance for you.