Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clojure-fill-paragraph acts incorrectly in variable docstring #438

Closed
raxod502 opened this issue Jul 18, 2017 · 2 comments
Closed

clojure-fill-paragraph acts incorrectly in variable docstring #438

raxod502 opened this issue Jul 18, 2017 · 2 comments

Comments

@raxod502
Copy link

raxod502 commented Jul 18, 2017

Expected behavior

Given the following text in clojure-mode, with point represented by |:

(def my-example-variable
  "It has a very long docstring. So long, in fact, that it wraps onto multiple lines! This is to demonstrate what happens when the docstring wraps over three lines.|"
  nil)

Pressing M-q should yield the following:

(def my-example-variable
  "It has a very long docstring. So long, in fact, that it wraps onto
  multiple lines! This is to demonstrate what happens when the
  docstring wraps over three lines.|"
  nil)

Actual behavior

The initial value of the variable is wrapped onto the same line as the docstring:

(def my-example-variable
  "It has a very long docstring. So long, in fact, that it wraps onto
  multiple lines! This is to demonstrate what happens when the
  docstring wraps over three lines."  nil)

Steps to reproduce the problem

Run emacs -Q, install clojure-mode, and open a Clojure file. Then see the "Expected behavior" section.

Environment & Version information

clojure-mode version information

clojure-mode (version 5.7.0-snapshot)

I am running revision 197298e of clojure-mode using straight.el.

Emacs version

GNU Emacs 25.2.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1911))

Installed by brew cask install emacs, running in the terminal.

Operating system

                -/+:.           raxod502@[redacted]
               :++++.           ----------------------------
              /+++/.            OS: OS X El Capitan 10.11.6 15G1510 x86_64
      .:-::- .+/:-``.::-        Model: MacBookPro11,3
   .:/++++++/::::/++++++/:`     Kernel: 15.6.0
 .:///////////////////////:`    Uptime: 39 days, 46 minutes
 ////////////////////////`      Packages: 355
-+++++++++++++++++++++++`       Shell: zsh 5.3.1
/++++++++++++++++++++++/        Resolution: 3008x1692@2x, 1440x900@2x
/sssssssssssssssssssssss.       DE: Aqua
:ssssssssssssssssssssssss-      WM: Quartz Compositor
 osssssssssssssssssssssssso/`   WM Theme: Blue
 `syyyyyyyyyyyyyyyyyyyyyyyy+`   Terminal: iTerm2
  `ossssssssssssssssssssss/     Terminal Font: InputMono-Medium 14
    :ooooooooooooooooooo+.      CPU: Intel i7-4980HQ (8) @ 2.80GHz
     `:+oo+/:-..-:/+o+/-        GPU: Intel Iris Pro, NVIDIA GeForce GT 750M
                                Memory: 4322MiB / 16384MiB

Commentary

Filling works correctly for functions. I presume that one of regexes must be tweaked in clojure-fill-paragraph, as the current ones apparently only recognize a vector as terminating the docstring.

(defun clojure-fill-paragraph (&optional justify)
  "Like `fill-paragraph', but can handle Clojure docstrings.

If JUSTIFY is non-nil, justify as well as fill the paragraph."
  (if (clojure-in-docstring-p)
      (let ((paragraph-start
             (concat paragraph-start
                     "\\|\\s-*\\([(:\"[]\\|~@\\|`(\\|#'(\\)"))
            (paragraph-separate
             (concat paragraph-separate "\\|\\s-*\".*[,\\.]$"))
            (fill-column (or clojure-docstring-fill-column fill-column))
            (fill-prefix (clojure-docstring-fill-prefix)))
        (fill-paragraph justify))
    (let ((paragraph-start (concat paragraph-start
                                   "\\|\\s-*\\([(:\"[]\\|`(\\|#'(\\)"))
          (paragraph-separate
           (concat paragraph-separate "\\|\\s-*\".*[,\\.[]$")))
      (or (fill-comment-paragraph justify)
          (fill-paragraph justify))
      ;; Always return `t'
      t)))
vspinu added a commit to vspinu/clojure-mode that referenced this issue Aug 5, 2017
@raxod502
Copy link
Author

@bbatsov Thanks, it works now. However, I prefer to redefine defonce so that it takes a docstring, and my example is broken again when I replace def with defonce:

(defonce my-example-variable
  "It has a very long docstring. So long, in fact, that it wraps onto multiple lines! This is to demonstrate what happens when the docstring wraps over three lines.|"
  nil)

This seems reasonable since I'm extending Clojure in a nonstandard way. However, it is possible for me to customize clojure-mode so that it recognizes defonce as taking a docstring?

raxod502 added a commit to radian-software/radian that referenced this issue Aug 20, 2017
@vspinu
Copy link
Contributor

vspinu commented Aug 20, 2017

It might make sense to apply that "fill" fix to all strings, not just doc-strings.

slipset pushed a commit to slipset/clojure-mode that referenced this issue Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants