Skip to content

Commit 958b310

Browse files
committed
Make session calculating from buffer work properly.
1 parent 9a6b08f commit 958b310

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

haskell-session.el

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,21 @@
119119

120120
(defun haskell-session-from-buffer ()
121121
"Get the session based on the buffer."
122-
(when (buffer-file-name)
123-
(let ((sessions (remove-if-not (lambda (session)
124-
(haskell-is-prefix-of (file-name-directory (buffer-file-name))
125-
(haskell-session-cabal-dir session)))
126-
haskell-sessions)))
127-
(sort sessions (lambda (a b) (< (length (haskell-session-cabal-dir a))
128-
(length (haskell-session-cabal-dir b)))))
129-
(when (consp sessions)
130-
(car sessions)))))
122+
(when (and (buffer-file-name)
123+
(consp haskell-sessions))
124+
(reduce (lambda (acc a)
125+
(if (haskell-is-prefix-of (haskell-session-cabal-dir a)
126+
(file-name-directory (buffer-file-name)))
127+
(if acc
128+
(if (and
129+
(> (length (haskell-session-cabal-dir a))
130+
(length (haskell-session-cabal-dir acc))))
131+
a
132+
acc)
133+
a)
134+
acc))
135+
haskell-sessions
136+
:initial-value nil)))
131137

132138
(defun haskell-session-new ()
133139
"Make a new session."

haskell-string.el

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
;;;###autoload
1717
(defun haskell-is-prefix-of (x y)
1818
"Is x string a prefix of y string?"
19-
(string= (substring x 0 (min (length x) (length y)))
20-
(substring y 0 (min (length x) (length y)))))
19+
(string= x (substring y 0 (min (length y) (length x)))))
2120

2221
(defun haskell-string ())
2322

0 commit comments

Comments
 (0)