How should multiline protocol method docstrings be formatted? - clojure

Multiline function or protocol docstrings can be easily formatted:
(defn foo
"Does a very complicated thing that I need to explain in excruciating detail.
Firstly, this function stringifies x with the standard greeting of 'Hello'.
Secondly, it appends the necessary exclamation point to the resulting string.
Finally, it prints the resulting result to *out*, followed by a newline and
the appropriate flush."
[x]
(println (str "Hello, " x "!")))
(defprotocol Bar
"A retail business establishment that serves alcoholic beverages, such as
beer, wine, liquor, cocktails, and other beverages like mineral water and soft
drinks and often sells snack foods, like crisps or peanuts, for consumption on
premises.")
But what about that inevitable combination of the two: protocol methods? Should they just spill onto the next line with two-space indentation?
(defprotocol Baz
(qux [thing2 thing1] "Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat."))
That looks fine in code, but if I call (doc qux), I get
-------------------------
user/qux
([thing2 thing1])
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
and now the first line looks quite odd. That's the only option that doesn't cause Emacs' M-q to work against you, so something like this won't fly:
(defprotocol Baz
(qux [thing2 thing1]
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat."))
And even if that didn't break autoformat, it just looks kind of strange to me.
So should I give up? Should I only use very short docstrings for protocol methods, and maybe just include more comprehensive documentation in the protocol's main docstring?
(defprotocol Baz
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat."
(qux [thing2 thing1] "Does a thing to thing1 depending on thing2."))
Or is there a Better Way?

I have found this awkward too, but end up using your middle way (with the comment starting on the next line after the argument list, by itself), and don’t find that it looks odd. It definitely produces the best looking output from (doc ...).
I originally wrote that I have no conflict between this approach and M-q, but I just did more experimentation and think I found the issue you were raising. If I hit M-q inside the doc string, which is all I ever routinely do, it works fine. But if I do it outside the doc string inside the defprotocol form, yeah, it shoves the first lines over too far. So, would moving to inside the string before reflowing it work for you?
To be honest, I most often look at my API doc as a web site produced by codox these days, though. So I am formatting it as Markdown, and paying slightly less attention to its format and readability as plain text.

Related

Using negative lookahead to exclude strings with condition but not ones longer than certain number of characters

I have this find regex:
^(?=.{35})(?!.*(?:-\h)).{0,35}[\h.]
It matches every line until the last whitespace/dot before the 35th position of the line, it also excludes lines starting with a dash.
Now I want to include lines starting with a dash and longer than 35 characters.
I tried with:
^(?=.{35})(?!.*(?:-\h.{0,35})).{0,35}[\h.]
But it doesn't work as expected.
What am I doing wrong?
Example text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
- Include this line Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
- This line is too short.
Thanks
Matching at least 35 chars after the - can be done using ^-.{35,} If you want to match both, you could use an alternation | matching either of the alternatives:
^(?:(?=.{35})(?!.*(?:-\h)).{0,35}[\h.]|-.{35,})
Regex demo

RegexExtract in Google Sheets for all occurences of seed list?

I am trying to extract a comma separated list of matching phrases in Google Sheets.
I have a Named Range 'Matchlist' =
sit amet
Ut enim
commodo consequat
Cell A1 =
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
In cell B1 the desired output would be:
sit amet,Ut enim,commodo consequat
I have been trying to use REGEXEXTRACT to do, but can only output the first match....
Any ideas or alternatives?
try:
=ARRAYFORMULA(SUBSTITUTE(REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
IF(REGEXMATCH(IFERROR(SPLIT(IFNA(REGEXREPLACE(A1:A,
"(sit amet)|(Ut enim)|(commodo consequat)", "♥$1$2$3♦♥")), "♥")), "♦"),
IFERROR(SPLIT(IFNA(REGEXREPLACE(A1:A,
"(sit amet)|(Ut enim)|(commodo consequat)", "♥$1$2$3♦♥")), "♥")), ))
,,99^99))), "♦$", ), "♦", ","))

REGEX - Select multiple lines unless it finds the defined stop charecter

I have a String
Lorem ipsum dolor sit amet
*consectetur adipiscing elit
sed do eiusmod tempor incididunt*
ut labore et dolore magna aliqua
Ut enim ad minim veniam.
now I want to select the * content *
this [*](.*?)[*] is my current regex, but it's working with a single line
*consectetur adipiscing elit*
How do I make it multiline?
This REGEX worked for me [*]([\\s\\S]*?)[*]

Sending an action to containing component

If I have two components:
nav-menu
nav-button
and nav-menu is a block component that would contain nav-button like so:
{{#nav-menu}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
{{nav-button}}
{{/nav-menu}}
I'd like the button to be able to directly send an action to the menu to tell it to toggle it's visibility state. I guess if I hook into a mutux point in Controller then I could do something like:
{{#nav-menu toggleNavigation=mutex}}
{{nav-button action=mutex}}
{{/nav-menu}}
Is this the only way? Just looking for the most graceful, ember-centric way of doing this.
I've run into this issue before and unfortunately, there's no way in the public API to do this. When creating a block component, anything rendered inside of it has the context of the outer scope, not the component. It's unfortunate that there's no way to change this behavior, but it really does make sense.
I would say that the way you've proposed is the best way to handle this situation: have a variable on the controller that's passed to the outer component. It's inline with Ember's "data down, actions up" philosophy.

Movable Type: How do I strip out all HTML and more

In <mt:EntryBody> I have couple of images and caption imbedded in the entry.
I want to strip out all the html for publishing in rss.
Here is my entry formatting:
<img src="/path/to/img.jpg">
<div style="text-align:right">Image Caption</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse</p>
If I do this:
<mt:EntryBody remove_html="1">
This strips out all HTML elements with EntryBody but I would also like to take out Image Caption part because it look weird without referencing image.
How do I accomplish this?
If you are using MT 4/5 Pro the easiest way to handle this is to have your image and caption in custom fields, then you can selectively output them into the appropriate templates. If it is in the content then something like this will be quite difficult, even with regex as Abe Miessler pointed out.
Prevailing wisdom says that you should not use regex to parse HTML. Could you convert it to XHTML and then use xslt/xpath to do what you want instead?
If you can, take a look at:
HTML Tidy
SGML Reader