-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
#44 Separate one-line header from next text block by paragraph-separate #45
Conversation
760a76d
to
497bb8b
Compare
@bbatsov It is really a pity! I even already tried a version-depending |
@bbatsov Okay, the new macro |
I think it might be simpler to just avoid using |
In
Therein, Note also that looks like the free-variable problem in |
I'm well aware of its status, but this was a contentious feature even in Common Lisp (where it originated), that's why I always avoid it. In general I always avoid Anyways, if you feel very strongly about it I can live with its usage. |
The thing that makes a basic implementation of IMHO: If you exclude If you are curious you can have a look at the destructuring binding-capabilities of https://ccrma.stanford.edu/CCRMA/Courses/AlgoComp/cm/doc/contrib/lispstyle.html A recursive search for |
@bbatsov Hope you are more comfortable with the latest version. |
adoc-mode.el
Outdated
(defun adoc-map-intervals (fun property &optional beg end object) | ||
"Apply FUN to all intervals of PROPERTY in OBJECT in the region from BEG to END. | ||
FUN is called with two arguments: the beginning and the end of the interval." | ||
(unless object (setq object (current-buffer))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you just use let
and something like (or beg (...))
. Using setq
to establish initial bindings is quite uncommon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many techniques for assigning default arguments.
The unless ... setq
-Method is one of the usual ones. Examples:
string
ofput-image
name
of `abbrev-insertbuffer
ofapropos-local-variable
- and many more...
It works well since function arguments are lexically bound args and setq is a special form that can handle lexically bound args. The quote in (setq sym val)
is not really evaluated in the sense of (set 'sym val)
which couldn't handle lexically bound args well.
adoc-mode.el
Outdated
(unless end (setq end (point-max))) | ||
(let (end-interval) | ||
(while | ||
(progn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
progn
is redundant in a while
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's your condition, not the body of the while
. Might be good to move something in the body and just check for the final state here, as now it looks pretty weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the usual loop with condition at the end.
Example: https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/jit-lock.el#n324
adoc-mode.el
Outdated
(setq end-interval (next-single-property-change beg property object end)) | ||
(funcall fun beg end-interval) | ||
(setq beg end-interval) | ||
(null (= end-interval end)))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this null
check needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If end
is given as buffer position next-single-property-change
returns that buffer position if no further property change is found. And that also indicates the last interval.
adoc-mode.el
Outdated
val adoc-buffer))) | ||
(adoc-map-intervals | ||
(lambda (pos next) | ||
(let ((val (get-text-property pos 'face))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also when-let
that would simplify this code a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know when-let
but I didn't know whether you like it.
It was long in subr-x.el
instead of subr.el
. Therefore, it was considered as seldom used feature:
commit b05a103ea7a26b2f4099a613015d9f1abdc39a4d
Author: Lars Ingebrigtsen larsi@gnus.org
Date: Sat Apr 30 16:42:44 2022 +0200Move the when-let family of macros to subr.el
- lisp/subr.el (internal--build-binding)
(internal--build-bindings): Moved from subr-x.el and rewritten to
not use the threading macro.
(if-let*, when-let*, and-let*, if-let, when-let): Moved from
subr-x.el. This avoids breaking the build every time somebody
uses these macros in functions that end up being called during
bootstrap.
Won't in the simpler to convert your range to a list and map over it or use I'm inclined to agree that the version with |
I think that would even complicate things since it just adds one more structural element: an additional list. Or maybe, I misunderstood you. |
My point is that usually intervals/ranges are represented as lists in programming languages. That's why converting the boundaries to a list seems reasonable to me, but if you have concerns about this you ca just revert to the cl-loop solution. |
@bbatsov Instead of resetting the changes I really reverted them to keep the other version in the database. I am merging this version now, since we already discussed it in some length. |
Move one-line header regexp from
adoc-re-paragraph-start
toadoc-re-paragraph-separate
.paragraph-separate
is merged intoparagraph-start
anyway.This should fix #44.