haskell-mode icon indicating copy to clipboard operation
haskell-mode copied to clipboard

Seperating haskell and cabal mode

Open puff-paddy opened this issue 6 months ago • 10 comments

Various major modes for haskell exist that are not haskell-mode, (haskell-ts-mode, haskell-ng-mode), and users of both are forced to pull haskell-mode since it provides a major mode for cabal. Would it be practical to support cabal-mode from haskell-mode in its own package?

puff-paddy avatar Sep 07 '25 11:09 puff-paddy

Probably, yes. The steps we'd need to follow would be approximately the following:

  • Create a new repo called cabal-mode with cabal.el, starting out as a copy of haskell-cabal.el.
  • Change all the haskell-cabal- identifier prefixes to cabal-.
  • Remove the (require 'haskell-utils) and figure out what would break. If anything, fix it if practical.
  • Publish a corresponding cabal package on MELPA and/or ELPA.
  • Remove haskell-cabal.el from haskell-mode, and perhaps (though probably not) make haskell-mode depend on the cabal package.

This is also relevant to my interests, because I'm personally working with haskell-ts-mode instead of haskell-mode. However, I'm not working much with Haskell at the moment, so I'm unlikely to work on the above steps myself.

purcell avatar Sep 08 '25 13:09 purcell

Probably, yes. The steps we'd need to follow would be approximately the following:

* Create a new repo called `cabal-mode` with `cabal.el`, starting out as a copy of `haskell-cabal.el`.

* Change all the `haskell-cabal-` identifier prefixes to `cabal-`.

* Remove the `(require 'haskell-utils)` and figure out what would break. If anything, fix it if practical.

* Publish a corresponding `cabal` package on MELPA and/or ELPA.

* Remove `haskell-cabal.el` from `haskell-mode`, and _perhaps_ (though probably not) make `haskell-mode` depend on the `cabal` package.

This is also relevant to my interests, because I'm personally working with haskell-ts-mode instead of haskell-mode. However, I'm not working much with Haskell at the moment, so I'm unlikely to work on the above steps myself.

I spent a lot of time writing code for my personal projects during the summer. Also it feels like haskell-mode is a big project, it is hard to get a good understanding of it, I dont know where to start. But I would love to get into haskell-mode and I would be like to help with this issue. I can create a new repo, in my account I guess since I dont have haskell organization permissions and separate the cabal mode into that and ping you when I am getting somewhere.

webdevred avatar Sep 08 '25 14:09 webdevred

@webdevred how is it going with separating the cabal mode?

puff-paddy avatar Sep 19 '25 15:09 puff-paddy

That sounds good, @webdevred — ping me if you need anything, or when there's anything to show. In due course we could then fold it back into this org for community maintenance.

purcell avatar Sep 22 '25 14:09 purcell

Hello @puff-paddy, Update from my side: So far I found three definitions in haskell-utils.el used by haskell-cabal.el, they are haskell-mode-toggle-interactive-prompt-state along with its toggle variable haskell-mode-interactive-prompt-state and haskell-utils-read-directory-name.

haskell-utils-read-directory-name, however is only used in haskell-cabal-get-dir, a function which is not used inside haskell-cabal.el but it is used in haskell-session.el.

This is is example of where haskell-mode-toggle-interactive-prompt-state is used:

(defun haskell-cabal-find-or-create-source-file ()
  "Open the source file this line refers to."
  (interactive)
  (let* ((src-dirs (append (haskell-cabal-subsection-entry-list
                            (haskell-cabal-section) "hs-source-dirs")
                           '("")))
         (base-dir (file-name-directory (buffer-file-name)))
         (filename (haskell-cabal-line-filename)))
    (when filename
      (let ((candidates
             (delq nil (mapcar
                        (lambda (dir)
                          (let ((file (haskell-cabal-join-paths base-dir
                                                                dir
                                                                filename)))
                            (when (and (file-readable-p file)
                                       (not (file-directory-p file)))
                              file)))
                        src-dirs))))
        (if (null candidates)
            (unwind-protect
                (progn
                  (haskell-mode-toggle-interactive-prompt-state)
                  (let* ((src-dir
                          (haskell-cabal-join-paths base-dir
                                                    (or (car src-dirs) "")))
                         (newfile (haskell-cabal-join-paths src-dir filename))
                         (do-create-p (y-or-n-p (format "Create file %s ?" newfile))))
                    (when do-create-p
                      (find-file-other-window newfile ))))
              (haskell-mode-toggle-interactive-prompt-state t))
          (find-file-other-window (car candidates)))))))

haskell-cabal-find-or-create-source-file is bound to C-c C-f in the cabal mode.

I plan to clean up my code and publish my code later, maybe tomorrow or during the coming week and proceed to make a package in melpa or elpa.

webdevred avatar Sep 27 '25 17:09 webdevred

No worries, take your time

puff-paddy avatar Oct 08 '25 14:10 puff-paddy

No worries, take your time

Update: I have published my cabal-mode package as a draft, we will probably discuss a bit how to improve it before merging it into melpa.

webdevred avatar Oct 22 '25 17:10 webdevred

Since cabal mode has been merged to melpa thanks to @webdevred , are there plans to remove haskell-cabal.el and perhaps add cabal-mode as a dependency

puff-paddy avatar Nov 21 '25 15:11 puff-paddy

Since cabal mode has been merged to melpa thanks to @webdevred , are there plans to remove haskell-cabal.el and perhaps add cabal-mode as a dependency

I would be happy help with this part as well, if @purcell thinks we should do this.

webdevred avatar Nov 21 '25 17:11 webdevred

Yeah, it would make sense to remove haskell-cabal.el. In a purist sense, haskell-mode shouldn't really depend on the cabal-mode package. Over time, haskell-mode has turned into a big Haskell IDE bundle, which isn't super desirable IMO, and static package dependencies make it hard to swap out non-core portions.

purcell avatar Nov 24 '25 17:11 purcell