Skip to content

Commit e33d5d8

Browse files
committed
Merge pull request #1136 from fice-t/sticky
Add front-sticky property to read-only text in REPL
2 parents 9aa1e73 + ab8be6e commit e33d5d8

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

haskell-interactive-mode.el

+38-34
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,24 @@ do the
298298
(defun haskell-interactive-mode-prompt (&optional session)
299299
"Show a prompt at the end of the REPL buffer.
300300
If SESSION is non-nil, use the REPL buffer associated with
301-
SESSION, otherwise operate on the current buffer.
302-
"
301+
SESSION, otherwise operate on the current buffer."
303302
(with-current-buffer (if session
304303
(haskell-session-interactive-buffer session)
305304
(current-buffer))
306305
(goto-char (point-max))
307-
(insert (propertize haskell-interactive-prompt
308-
'font-lock-face 'haskell-interactive-face-prompt
309-
'read-only t
310-
'rear-nonsticky t
311-
'prompt t))
306+
(let ((prompt (propertize haskell-interactive-prompt
307+
'font-lock-face 'haskell-interactive-face-prompt
308+
'prompt t
309+
'read-only t
310+
'rear-nonsticky t)))
311+
;; At the time of writing, front-stickying the first char gives an error
312+
;; Has unfortunate side-effect of being able to insert before the prompt
313+
(insert (substring prompt 0 1)
314+
(propertize (substring prompt 1)
315+
'front-sticky t)))
312316
(let ((marker (set (make-local-variable 'haskell-interactive-mode-prompt-start)
313317
(make-marker))))
314-
(set-marker marker
315-
(point)
316-
(current-buffer))
317-
(when nil
318-
(let ((o (make-overlay (point) (point-max) nil nil t)))
319-
(overlay-put o 'line-prefix (make-string (length haskell-interactive-prompt)
320-
? )))))
318+
(set-marker marker (point)))
321319
(when haskell-interactive-mode-scroll-to-bottom
322320
(haskell-interactive-mode-scroll-to-bottom))))
323321

@@ -328,9 +326,10 @@ SESSION, otherwise operate on the current buffer.
328326
(insert (ansi-color-apply
329327
(propertize text
330328
'font-lock-face 'haskell-interactive-face-result
331-
'rear-nonsticky t
332-
'read-only t
329+
'front-sticky t
333330
'prompt t
331+
'read-only t
332+
'rear-nonsticky t
334333
'result t)))
335334
(haskell-interactive-mode-handle-h)
336335
(let ((marker (set (make-local-variable 'haskell-interactive-mode-result-end)
@@ -365,22 +364,25 @@ SESSION, otherwise operate on the current buffer.
365364
(save-excursion
366365
(haskell-interactive-mode-goto-end-point)
367366
(let ((lines (string-match "^\\(.*\\)\n\\([[:unibyte:][:nonascii:]]+\\)" message)))
368-
(when lines
369-
(insert (propertize (concat (match-string 1 message) "\n")
370-
'font-lock-face type
371-
'read-only t
372-
'rear-nonsticky t
373-
'expandable t))
374-
(insert (propertize (concat (match-string 2 message) "\n")
375-
'font-lock-face type
376-
'read-only t
377-
'rear-nonsticky t
378-
'collapsible t
379-
'invisible haskell-interactive-mode-hide-multi-line-errors
380-
'message-length (length (match-string 2 message)))))
381-
(unless lines
367+
(if lines
368+
(progn
369+
(insert (propertize (concat (match-string 1 message) "\n")
370+
'expandable t
371+
'font-lock-face type
372+
'front-sticky t
373+
'read-only t
374+
'rear-nonsticky t))
375+
(insert (propertize (concat (match-string 2 message) "\n")
376+
'collapsible t
377+
'font-lock-face type
378+
'front-sticky t
379+
'invisible haskell-interactive-mode-hide-multi-line-errors
380+
'message-length (length (match-string 2 message))
381+
'read-only t
382+
'rear-nonsticky t)))
382383
(insert (propertize (concat message "\n")
383384
'font-lock-face type
385+
'front-sticky t
384386
'read-only t
385387
'rear-nonsticky t)))))))
386388

@@ -390,6 +392,7 @@ SESSION, otherwise operate on the current buffer.
390392
(save-excursion
391393
(haskell-interactive-mode-goto-end-point)
392394
(insert (propertize message
395+
'front-sticky t
393396
'read-only t
394397
'rear-nonsticky t)))))
395398

@@ -736,8 +739,7 @@ wrapped in compiler directive at the top of FILE."
736739
(error "don't know where to find %S" file)))))))
737740

738741
(defun haskell-interactive-session ()
739-
"Get the `haskell-session', throw an error if it's not
740-
available."
742+
"Get the `haskell-session', throw an error if it's not available."
741743
(or (haskell-session-maybe)
742744
(haskell-session-assign
743745
(or (haskell-session-from-buffer)
@@ -751,8 +753,8 @@ wrapped in compiler directive at the top of FILE."
751753
buffer. Maybe run M-x haskell-process-restart?")))
752754

753755
(defun haskell-interactive-mode-do-presentation (expr)
754-
"Present the given expression. Requires the `present` package
755-
to be installed. Will automatically import it qualified as Present."
756+
"Present the given expression. Requires the `present' package
757+
to be installed. Will automatically import it qualified as Present."
756758
(let ((p (haskell-interactive-process)))
757759
;; If Present.code isn't available, we probably need to run the
758760
;; setup.
@@ -1083,6 +1085,7 @@ don't care when the thing completes as long as it's soonish."
10831085
(concat message "\n")
10841086
mode)
10851087
(propertize (concat message "\n")
1088+
'front-sticky t
10861089
'read-only t
10871090
'rear-nonsticky t))))))
10881091

@@ -1118,6 +1121,7 @@ don't care when the thing completes as long as it's soonish."
11181121
(save-excursion
11191122
(haskell-interactive-mode-goto-end-point)
11201123
(insert (propertize message
1124+
'front-sticky t
11211125
'font-lock-face 'haskell-interactive-face-garbage
11221126
'read-only t
11231127
'rear-nonsticky t)))))

0 commit comments

Comments
 (0)