Subject: Re: bug#31726: confirming proposed change

From: Jack Hill <[email-masked]>
Date: Fri, 8 Jun 2018 15:46:46 -0400 (EDT)

On Fri, 8 Jun 2018, Ludovic Courtès wrote:

> Hi,
>
> Jack Hill <[email-masked]> skribis:
>
>> Sure, I'll give make a path a go. You're thinking that I should try
>> applying the changes that the commit introduced as part of our package
>> definition?
>
> Yes, either that or use a snapshot of upstream haskell-mode.

I have started workign on a patch implementing the former. I've included 
what I have so far below, but it's not ready to be included in the 
distribution because not all of the tests pass. Maybe this is because the 
one patch shouldn't be applied in issolation and it would be bettter to 
take the snapshot approach?

Otherwise, is what I did with the package revision reasonable?

Thanks,
Jack

>From 62ae1a14c48f3d70e6f47ffd6de60a0b9af9d43f Mon Sep 17 00:00:00 2001
From: Jack Hill <[email-masked]>
Date: Thu, 7 Jun 2018 22:54:12 -0400
Subject: [PATCH] Patch haskell-mode to remove unused lexical variables

---
  gnu/packages/emacs.scm                             | 174 +++++++++++----------
  ...ell-mode-removed-unused-lexical-variables.patch |  42 +++++
  2 files changed, 131 insertions(+), 85 deletions(-)
  create mode 100644 gnu/packages/patches/haskell-mode-removed-unused-lexical-variables.patch

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index e90660a23..5e93cd2b8 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -631,92 +631,96 @@ only a handful of functions that are not resource-specific.")
      (license license:gpl3+)))

  (define-public haskell-mode
-  (package
-    (name "haskell-mode")
-    (version "16.1")
-    (source (origin
-              (method url-fetch)
-              (file-name (string-append name "-" version ".tar.gz"))
-              (uri (string-append
-                    "https://github.com/haskell/haskell-mode/archive/v"
-                    version ".tar.gz"))
-              (sha256
-               (base32 "0g6lcjw7lcgavv3yrd8xjcyqgfyjl787y32r1z14amw2f009m78h"))))
-    (inputs
-     `(("emacs-el-search" ,emacs-el-search) ; for tests
-       ("emacs-stream" ,emacs-stream)))     ; for tests
-    (propagated-inputs
-     `(("emacs-dash" ,emacs-dash)))
-    (native-inputs
-     `(("emacs" ,emacs-minimal)
-       ("texinfo" ,texinfo)))
-    (build-system gnu-build-system)
-    (arguments
-     `(#:make-flags (list (string-append "EMACS="
-                                         (assoc-ref %build-inputs "emacs")
-                                         "/bin/emacs"))
-       #:modules ((ice-9 match)
-                  (srfi srfi-26)
-                  ,@%gnu-build-system-modules)
-       #:phases
-       (modify-phases %standard-phases
-         (delete 'configure)
-         (add-before
-          'build 'pre-build
-          (lambda* (#:key inputs #:allow-other-keys)
-            (define (el-dir store-dir)
-              (match (find-files store-dir "\\.el$")
-                ((f1 f2 ...) (dirname f1))
-                (_ "")))
-
-            (let ((sh (string-append (assoc-ref inputs "bash") "/bin/sh")))
-              (define emacs-prefix? (cut string-prefix? "emacs-" <>))
-
-              (setenv "SHELL" "sh")
-              (setenv "EMACSLOADPATH"
-                      (string-concatenate
-                       (map (match-lambda
-                              (((? emacs-prefix? name) . dir)
-                               (string-append (el-dir dir) ":"))
-                              (_ ""))
-                            inputs)))
-              (substitute* (find-files "." "\\.el") (("/bin/sh") sh))
-              (substitute* "tests/haskell-code-conventions.el"
-                ;; Function name recently changed in "emacs-el-search".
-                (("el-search--search-pattern") "el-search-forward")
-                ;; Don't contact home.
-                (("\\(when \\(>= emacs-major-version 25\\)")
-                 "(require 'el-search) (when nil"))
-              #t)))
-         (replace
-          'install
-          (lambda* (#:key outputs #:allow-other-keys)
-            (let* ((out (assoc-ref outputs "out"))
-                   (el-dir (string-append out "/share/emacs/site-lisp"))
-                   (doc (string-append
-                         out "/share/doc/haskell-mode-" ,version))
-                   (info (string-append out "/share/info")))
-              (define (copy-to-dir dir files)
-                (for-each (lambda (f)
-                            (install-file f dir))
-                          files))
-
-              (with-directory-excursion "doc"
-                (unless (zero? (system* "makeinfo" "haskell-mode.texi"))
-                  (error "makeinfo failed"))
-                (install-file "haskell-mode.info" info))
-               (copy-to-dir doc '("CONTRIBUTING.md" "NEWS" "README.md"))
-               (copy-to-dir el-dir (find-files "." "\\.elc?"))
-               ;; These are part of other packages.
-               (with-directory-excursion el-dir
-                 (for-each delete-file '("dash.el" "ert.el")))
-               #t))))))
-    (home-page "https://github.com/haskell/haskell-mode")
-    (synopsis "Haskell mode for Emacs")
-    (description
-     "This is an Emacs mode for editing, debugging and developing Haskell
+  (let ((release "16.1")
+        (revision "1"))
+    (package
+      (name "haskell-mode")
+      (version (string-append release "-" revision))
+      (source (origin
+                (method url-fetch)
+                (file-name (string-append name "-" release ".tar.gz"))
+                (uri (string-append
+                      "https://github.com/haskell/haskell-mode/archive/v"
+                      release ".tar.gz"))
+                (sha256
+                 (base32 "0g6lcjw7lcgavv3yrd8xjcyqgfyjl787y32r1z14amw2f009m78h"))
+                (patches
+                 (search-patches "haskell-mode-removed-unused-lexical-variables.patch"))))
+      (inputs
+       `(("emacs-el-search" ,emacs-el-search) ; for tests
+         ("emacs-stream" ,emacs-stream)))     ; for tests
+      (propagated-inputs
+       `(("emacs-dash" ,emacs-dash)))
+      (native-inputs
+       `(("emacs" ,emacs-minimal)
+         ("texinfo" ,texinfo)))
+      (build-system gnu-build-system)
+      (arguments
+       `(#:make-flags (list (string-append "EMACS="
+                                           (assoc-ref %build-inputs "emacs")
+                                           "/bin/emacs"))
+         #:modules ((ice-9 match)
+                    (srfi srfi-26)
+                    ,@%gnu-build-system-modules)
+         #:phases
+         (modify-phases %standard-phases
+           (delete 'configure)
+           (add-before
+               'build 'pre-build
+             (lambda* (#:key inputs #:allow-other-keys)
+               (define (el-dir store-dir)
+                 (match (find-files store-dir "\\.el$")
+                   ((f1 f2 ...) (dirname f1))
+                   (_ "")))
+
+               (let ((sh (string-append (assoc-ref inputs "bash") "/bin/sh")))
+                 (define emacs-prefix? (cut string-prefix? "emacs-" <>))
+
+                 (setenv "SHELL" "sh")
+                 (setenv "EMACSLOADPATH"
+                         (string-concatenate
+                          (map (match-lambda
+                                 (((? emacs-prefix? name) . dir)
+                                  (string-append (el-dir dir) ":"))
+                                 (_ ""))
+                               inputs)))
+                 (substitute* (find-files "." "\\.el") (("/bin/sh") sh))
+                 (substitute* "tests/haskell-code-conventions.el"
+                   ;; Function name recently changed in "emacs-el-search".
+                   (("el-search--search-pattern") "el-search-forward")
+                   ;; Don't contact home.
+                   (("\\(when \\(>= emacs-major-version 25\\)")
+                    "(require 'el-search) (when nil"))
+                 #t)))
+           (replace
+               'install
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let* ((out (assoc-ref outputs "out"))
+                      (el-dir (string-append out "/share/emacs/site-lisp"))
+                      (doc (string-append
+                            out "/share/doc/haskell-mode-" ,version))
+                      (info (string-append out "/share/info")))
+                 (define (copy-to-dir dir files)
+                   (for-each (lambda (f)
+                               (install-file f dir))
+                             files))
+
+                 (with-directory-excursion "doc"
+                   (unless (zero? (system* "makeinfo" "haskell-mode.texi"))
+                     (error "makeinfo failed"))
+                   (install-file "haskell-mode.info" info))
+                 (copy-to-dir doc '("CONTRIBUTING.md" "NEWS" "README.md"))
+                 (copy-to-dir el-dir (find-files "." "\\.elc?"))
+                 ;; These are part of other packages.
+                 (with-directory-excursion el-dir
+                   (for-each delete-file '("dash.el" "ert.el")))
+                 #t))))))
+      (home-page "https://github.com/haskell/haskell-mode")
+      (synopsis "Haskell mode for Emacs")
+      (description
+       "This is an Emacs mode for editing, debugging and developing Haskell
  programs.")
-    (license license:gpl3+)))
+      (license license:gpl3+))))

  (define-public flycheck
    (package
diff --git a/gnu/packages/patches/haskell-mode-removed-unused-lexical-variables.patch b/gnu/packages/patches/haskell-mode-removed-unused-lexical-variables.patch
new file mode 100644
index 000000000..a618df5fb
--- /dev/null
+++ b/gnu/packages/patches/haskell-mode-removed-unused-lexical-variables.patch
@@ -0,0 +1,42 @@
+From cee22450ee30e79952f594796721dc6b17798ee6 Mon Sep 17 00:00:00 2001
+From: Sascha Wilde <[email-masked]>
+Date: Fri, 23 Sep 2016 15:35:59 +0200
+Subject: [PATCH] Removed unused lexical variables.
+
+---
+ haskell-lexeme.el  | 3 +--
+ haskell-process.el | 4 +---
+ 2 files changed, 2 insertions(+), 5 deletions(-)
+
+diff --git a/haskell-lexeme.el b/haskell-lexeme.el
+index 4256a79..b832560 100644
+--- a/haskell-lexeme.el
++++ b/haskell-lexeme.el
+@@ -138,8 +138,7 @@ When match is successful, match-data will contain:
+   (match-text 2) - whole qualified identifier
+   (match-text 3) - unqualified part of identifier
+   (match-text 4) - closing backtick"
+-  (let ((begin (point))
+-        (match-data-old (match-data))
++  (let ((match-data-old (match-data))
+         first-backtick-start
+         last-backtick-start
+         qid-start
+diff --git a/haskell-process.el b/haskell-process.el
+index b4efba2..4f3f859 100644
+--- a/haskell-process.el
++++ b/haskell-process.el
+@@ -160,9 +160,7 @@ HPTYPE is the result of calling `'haskell-process-type`' function."
+ (defun haskell-process-log (msg)
+   "Effective append MSG to the process log (if enabled)."
+   (when haskell-process-log
+-    (let* ((append-to (get-buffer-create "*haskell-process-log*"))
+-           (windows (get-buffer-window-list append-to t t))
+-           move-point-in-windows)
++    (let* ((append-to (get-buffer-create "*haskell-process-log*")))
+       (with-current-buffer append-to
+         ;; point should follow insertion so that it stays at the end
+         ;; of the buffer
+-- 
+2.11.0
+
-- 
2.11.0