Skip to content

Commit c0855b4

Browse files
committed
Merge pull request #644 from geraldus/better-doc-strings-haskell-commands
Better doc strings in haskell-commands.el
2 parents 1d69617 + 24c8c58 commit c0855b4

File tree

1 file changed

+70
-52
lines changed

1 file changed

+70
-52
lines changed

haskell-commands.el

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
(haskell-process-start (haskell-interactive-session)))
4242

4343
(defun haskell-process-start (session)
44-
"Start the inferior Haskell process."
44+
"Start the inferior Haskell process with a given SESSION.
45+
You can create new session using function `haskell-session-make'."
4546
(let ((existing-process (get-process (haskell-session-name (haskell-interactive-session)))))
4647
(when (processp existing-process)
4748
(haskell-interactive-mode-echo session "Restarting process ...")
@@ -77,7 +78,7 @@
7778
process))
7879

7980
(defun haskell-process-send-startup (process)
80-
"Send the necessary start messages."
81+
"Send the necessary start messages to haskell PROCESS."
8182
(haskell-process-queue-command
8283
process
8384
(make-haskell-command
@@ -136,16 +137,18 @@ If I break, you can:
136137
(interrupt-process (haskell-process-process (haskell-commands-process))))
137138

138139
(defun haskell-process-reload-with-fbytecode (process module-buffer)
139-
"Reload FILE-NAME with -fbyte-code set, and then restore -fobject-code."
140+
"Query a PROCESS to reload MODULE-BUFFER with -fbyte-code set.
141+
Restores -fobject-code after reload finished.
142+
MODULE-BUFFER is the actual Emacs buffer of the module being loaded."
140143
(haskell-process-queue-without-filters process ":set -fbyte-code")
141144
(haskell-process-touch-buffer process module-buffer)
142145
(haskell-process-queue-without-filters process ":reload")
143146
(haskell-process-queue-without-filters process ":set -fobject-code"))
144147

145148
;;;###autoload
146149
(defun haskell-process-touch-buffer (process buffer)
147-
"Updates mtime on the file for BUFFER by queing a touch on
148-
PROCESS."
150+
"Query PROCESS to `:!touch` BUFFER's file.
151+
Use to update mtime on BUFFER's file."
149152
(interactive)
150153
(haskell-process-queue-command
151154
process
@@ -166,7 +169,8 @@ PROCESS."
166169
(defvar url-http-end-of-headers)
167170

168171
(defun haskell-process-hayoo-ident (ident)
169-
"Hayoo for IDENT, returns a list of modules asyncronously through CALLBACK."
172+
;; FIXME Obsolete doc string, CALLBACK is not used.
173+
"Hayoo for IDENT, return a list of modules asyncronously through CALLBACK."
170174
;; We need a real/simulated closure, because otherwise these
171175
;; variables will be unbound when the url-retrieve callback is
172176
;; called.
@@ -189,7 +193,7 @@ PROCESS."
189193
(warn "HTTP error %s fetching %s" url-http-response-status url)))))
190194

191195
(defun haskell-process-hoogle-ident (ident)
192-
"Hoogle for IDENT, returns a list of modules."
196+
"Hoogle for IDENT, return a list of modules."
193197
(with-temp-buffer
194198
(let ((hoogle-error (call-process "hoogle" nil t nil "search" "--exact" ident)))
195199
(goto-char (point-min))
@@ -203,7 +207,7 @@ PROCESS."
203207
"\n"))))))
204208

205209
(defun haskell-process-haskell-docs-ident (ident)
206-
"Search with haskell-docs for IDENT, returns a list of modules."
210+
"Search with haskell-docs for IDENT, return a list of modules."
207211
(cl-remove-if-not
208212
(lambda (a) (string-match "^[[:upper:]][[:alnum:]_'.]+$" a))
209213
(split-string
@@ -218,8 +222,7 @@ PROCESS."
218222
"\n")))
219223

220224
(defun haskell-process-import-modules (process modules)
221-
"Import `modules' with :m +, and send any import statements
222-
from `module-buffer'."
225+
"Query PROCESS `:m +' command to import MODULES."
223226
(when haskell-process-auto-import-loaded-modules
224227
(haskell-process-queue-command
225228
process
@@ -232,14 +235,14 @@ from `module-buffer'."
232235

233236
;;;###autoload
234237
(defun haskell-describe (ident)
235-
"Describe the given identifier."
238+
"Describe the given identifier IDENT."
236239
(interactive (list (read-from-minibuffer "Describe identifier: "
237240
(haskell-ident-at-point))))
238241
(let ((results (read (shell-command-to-string
239242
(concat "haskell-docs --sexp "
240243
ident)))))
241244
(help-setup-xref (list #'haskell-describe ident)
242-
(called-interactively-p 'interactive))
245+
(called-interactively-p 'interactive))
243246
(save-excursion
244247
(with-help-window (help-buffer)
245248
(with-current-buffer (help-buffer)
@@ -269,9 +272,10 @@ from `module-buffer'."
269272

270273
;;;###autoload
271274
(defun haskell-rgrep (&optional prompt)
272-
"Grep the effective project for the symbol at point. Very
273-
useful for codebase navigation. Prompts for an arbitrary regexp
274-
given a prefix arg."
275+
"Grep the effective project for the symbol at point.
276+
Very useful for codebase navigation.
277+
278+
Prompts for an arbitrary regexp given a prefix arg PROMPT."
275279
(interactive "P")
276280
(let ((sym (if prompt
277281
(read-from-minibuffer "Look for: ")
@@ -310,7 +314,11 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
310314

311315
;;;###autoload
312316
(defun haskell-process-do-type (&optional insert-value)
313-
"Print the type of the given expression."
317+
;; FIXME insert value functionallity seems to be missing.
318+
"Print the type of the given expression.
319+
320+
Given INSERT-VALUE prefix indicates that result type signature
321+
should be inserted."
314322
(interactive "P")
315323
(if insert-value
316324
(haskell-process-insert-type)
@@ -334,8 +342,10 @@ If PROMPT-VALUE is non-nil, request identifier via mini-buffer."
334342

335343
;;;###autoload
336344
(defun haskell-mode-jump-to-def-or-tag (&optional next-p)
337-
"Jump to the definition (by consulting GHCi), or (fallback)
338-
jump to the tag.
345+
;; FIXME NEXT-P arg is not used
346+
"Jump to the definition.
347+
Jump to definition of identifier at point by consulting GHCi, or
348+
tag table as fallback.
339349
340350
Remember: If GHCi is busy doing something, this will delay, but
341351
it will always be accurate, in contrast to tags, which always
@@ -359,16 +369,15 @@ position with `xref-pop-marker-stack'."
359369

360370
;;;###autoload
361371
(defun haskell-mode-goto-loc ()
362-
"Go to the location of the thing at point. Requires the :loc-at
363-
command from GHCi."
372+
"Go to the location of the thing at point.
373+
Requires the :loc-at command from GHCi."
364374
(interactive)
365375
(let ((loc (haskell-mode-loc-at)))
366376
(when loc
367377
(haskell-mode-goto-span loc))))
368378

369379
(defun haskell-mode-goto-span (span)
370-
"Jump to the span, whatever file and line and column it needs
371-
to to get there."
380+
"Jump to the SPAN, whatever file and line and column it needs to get there."
372381
(xref-push-marker-stack)
373382
(find-file (expand-file-name (plist-get span :path)
374383
(haskell-session-cabal-dir (haskell-interactive-session))))
@@ -377,8 +386,8 @@ to to get there."
377386
(forward-char (plist-get span :start-col)))
378387

379388
(defun haskell-process-insert-type ()
380-
"Get the identifer at the point and insert its type, if
381-
possible, using GHCi's :type."
389+
"Get the identifer at the point and insert its type.
390+
Use GHCi's :type if it's possible."
382391
(let ((ident (haskell-ident-at-point)))
383392
(when ident
384393
(let ((process (haskell-interactive-process))
@@ -405,17 +414,17 @@ possible, using GHCi's :type."
405414
(insert (format "%s\n" (replace-regexp-in-string "\n$" "" response)))))))))))))
406415

407416
(defun haskell-mode-find-def (ident)
408-
"Find definition location of identifier. Uses the GHCi process
409-
to find the location. Returns `nil' if it can't find the
410-
identifier or the identifier isn't a string.
417+
;; TODO Check if it possible to exploit `haskell-process-do-info'
418+
"Find definition location of identifier IDENT.
419+
Uses the GHCi process to find the location. Returns nil if it
420+
can't find the identifier or the identifier isn't a string.
411421
412422
Returns:
413423
414424
(library <package> <module>)
415425
(file <path> <line> <col>)
416426
(module <name>)
417-
nil
418-
"
427+
nil"
419428
(when (stringp ident)
420429
(let ((reply (haskell-process-queue-sync-request
421430
(haskell-interactive-process)
@@ -447,15 +456,15 @@ Returns:
447456

448457
;;;###autoload
449458
(defun haskell-mode-jump-to-def (ident)
450-
"Jump to definition of identifier at point."
459+
"Jump to definition of identifier IDENT at point."
451460
(interactive (list (haskell-ident-at-point)))
452461
(let ((loc (haskell-mode-find-def ident)))
453462
(when loc
454463
(haskell-mode-handle-generic-loc loc))))
455464

456465
(defun haskell-mode-handle-generic-loc (loc)
457-
"Either jump to or display a generic location. Either a file or
458-
a library."
466+
"Either jump to or echo a generic location LOC.
467+
Either a file or a library."
459468
(cl-case (car loc)
460469
(file (haskell-mode-jump-to-loc (cdr loc)))
461470
(library (message "Defined in `%s' (%s)."
@@ -465,8 +474,8 @@ a library."
465474
(elt loc 1)))))
466475

467476
(defun haskell-mode-loc-at ()
468-
"Get the location at point. Requires the :loc-at command from
469-
GHCi."
477+
"Get the location at point.
478+
Requires the :loc-at command from GHCi."
470479
(let ((pos (or (when (region-active-p)
471480
(cons (region-beginning)
472481
(region-end)))
@@ -503,6 +512,7 @@ GHCi."
503512

504513
;;;###autoload
505514
(defun haskell-process-cd (&optional not-interactive)
515+
;; FIXME optional arg is not used
506516
"Change directory."
507517
(interactive)
508518
(let* ((session (haskell-interactive-session))
@@ -515,7 +525,10 @@ GHCi."
515525
dir)))
516526

517527
(defun haskell-session-pwd (session &optional change)
518-
"Prompt for the current directory."
528+
"Prompt for the current directory.
529+
Return current working directory for SESSION.
530+
Optional CHANGE argument makes user to choose new working directory for SESSION.
531+
In this case new working directory path will be returned."
519532
(or (unless change
520533
(haskell-session-get session 'current-dir))
521534
(progn (haskell-session-set-current-dir
@@ -530,7 +543,8 @@ GHCi."
530543
(haskell-session-get session 'current-dir))))
531544

532545
(defun haskell-process-change-dir (session process dir)
533-
"Change the directory of the current process."
546+
"Change SESSION's current directory.
547+
Query PROCESS to `:cd` to directory DIR."
534548
(haskell-process-queue-command
535549
process
536550
(make-haskell-command
@@ -555,7 +569,7 @@ GHCi."
555569
":set -optP-include -optPdist/build/autogen/cabal_macros.h"))
556570

557571
(defun haskell-process-do-try-info (sym)
558-
"Get info of `sym' and echo in the minibuffer."
572+
"Get info of SYM and echo in the minibuffer."
559573
(let ((process (haskell-interactive-process)))
560574
(haskell-process-queue-command
561575
process
@@ -573,7 +587,7 @@ GHCi."
573587
(haskell-mode-message-line response)))))))
574588

575589
(defun haskell-process-do-try-type (sym)
576-
"Get type of `sym' and echo in the minibuffer."
590+
"Get type of SYM and echo in the minibuffer."
577591
(let ((process (haskell-interactive-process)))
578592
(haskell-process-queue-command
579593
process
@@ -684,7 +698,9 @@ happened since function invocation)."
684698

685699
;;;###autoload
686700
(defun haskell-process-generate-tags (&optional and-then-find-this-tag)
687-
"Regenerate the TAGS table."
701+
"Regenerate the TAGS table.
702+
If optional AND-THEN-FIND-THIS-TAG argument is present it is used with
703+
function `find-tag' after new table was generated."
688704
(interactive)
689705
(let ((process (haskell-interactive-process)))
690706
(haskell-process-queue-command
@@ -716,9 +732,10 @@ happened since function invocation)."
716732
(haskell-mode-message-line "Tags generated."))))))
717733

718734
(defun haskell-process-add-cabal-autogen ()
719-
"Add <cabal-project-dir>/dist/build/autogen/ to the ghci search
720-
path. This allows modules such as 'Path_...', generated by cabal,
721-
to be loaded by ghci."
735+
"Add cabal's autogen dir to the GHCi search path.
736+
Add <cabal-project-dir>/dist/build/autogen/ to GHCi seatch path.
737+
This allows modules such as 'Path_...', generated by cabal, to be
738+
loaded by GHCi."
722739
(unless (eq 'cabal-repl (haskell-process-type)) ;; redundant with "cabal repl"
723740
(let*
724741
((session (haskell-interactive-session))
@@ -730,8 +747,9 @@ to be loaded by ghci."
730747

731748
;;;###autoload
732749
(defun haskell-process-unignore ()
733-
"Unignore any files that were specified as being ignored by the
734-
inferior GHCi process."
750+
"Unignore any ignored files.
751+
Do not ignore files that were specified as being ignored by the
752+
inferior GHCi process."
735753
(interactive)
736754
(let ((session (haskell-interactive-session))
737755
(changed nil))
@@ -756,7 +774,7 @@ to be loaded by ghci."
756774

757775
;;;###autoload
758776
(defun haskell-session-change-target (target)
759-
"Set the build target for cabal repl"
777+
"Set the build TARGET for cabal REPL."
760778
(interactive "sNew build target:")
761779
(let* ((session haskell-session)
762780
(old-target (haskell-session-get session 'target)))
@@ -778,9 +796,9 @@ to be loaded by ghci."
778796
(goto-char (+ column (point)))))
779797

780798
(defun haskell-mode-buffer-apply-command (cmd)
781-
"Execute shell command CMD with current buffer as input and
782-
replace the whole buffer with the output. If CMD fails the buffer
783-
remains unchanged."
799+
"Execute shell command CMD with current buffer as input and output.
800+
Use buffer as input and replace the whole buffer with the
801+
output. If CMD fails the buffer remains unchanged."
784802
(set-buffer-modified-p t)
785803
(let* ((chomp (lambda (str)
786804
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" str)
@@ -826,7 +844,7 @@ remains unchanged."
826844

827845
;;;###autoload
828846
(defun haskell-mode-find-uses ()
829-
"Find uses of the identifier at point, highlight them all."
847+
"Find use cases of the identifier at point and highlight them all."
830848
(interactive)
831849
(let ((spans (haskell-mode-uses-at)))
832850
(unless (null spans)
@@ -835,7 +853,7 @@ remains unchanged."
835853
do (haskell-mode-make-use-highlight span)))))
836854

837855
(defun haskell-mode-make-use-highlight (span)
838-
"Make a highlight overlay at the given span."
856+
"Make a highlight overlay at the given SPAN."
839857
(save-window-excursion
840858
(save-excursion
841859
(haskell-mode-goto-span span)
@@ -853,8 +871,8 @@ remains unchanged."
853871
(point)))))))
854872

855873
(defun haskell-mode-uses-at ()
856-
"Get the locations of uses for the ident at point. Requires
857-
the :uses command from GHCi."
874+
"Get the locations of use cases for the ident at point.
875+
Requires the :uses command from GHCi."
858876
(let ((pos (or (when (region-active-p)
859877
(cons (region-beginning)
860878
(region-end)))

0 commit comments

Comments
 (0)