-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add on-the-fly easy score checking #27
base: main
Are you sure you want to change the base?
Conversation
I have added also a function that toggles the on-the-fly mode. By default is turned off. By the way I am not totally sure I autoload all the required functions, so a review on that would be idea. |
Let me quickly say "thank you" for the PR. I'll review it shortly. Default off is a good idea. In fact, for a feature like this, it is a requirement in my book. |
I agree that the default should be this feature being turned off. @ag91 it'd be good to include documentation, both in README.org and in writegood-mode.el, stating how to enable/disable this feature. |
@robstewart57 that makes perfect sense! Too functional oriented XD I will update with that change |
Hi, updated the README. Please review the style: I am not sure it fits
with the tone of the original text.
Also while writing I was thinking if it would make sense to make the
hooks customizable. For example, somebody may want to check a sentence
score even after a semicolon, rather than just a dot.
What do you think?
…On Wed 05 Dec 2018 at 12:39, Rob Stewart ***@***.***> wrote:
I agree that the default should be this feature being turned off.
@ag91 it'd be good to include documentation, both in README.org and in writegood-mode.el, stating how to enable/disable this feature.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
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.
@ag91 Thank you for this PR. It works and I like the idea behind the feature addition.
Before this gets merged, there are some changes to make the solution more robust and better integrate into emacs. If any of my comments are confusing, feel free to fire back. I'd like to make sure we have the conversations that we need to ship this feature.
writegood-mode.el
Outdated
;;;###autoload | ||
(defun writegood-reading-ease (&optional start end) | ||
"Flesch-Kincaid reading ease test in the region bounded by START and END. | ||
;;; BEGIN Score on the fly |
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.
What does BEGIN
mean to you here?
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 will remove this: it was only to delimit my additions while I was merging stuff in.
writegood-mode.el
Outdated
(let* ((params (writegood-fk-parameters start end)) | ||
(sentences (nth 0 params)) | ||
(words (nth 1 params)) | ||
(syllables (nth 2 params)) | ||
(score (- 206.835 (* 1.015 (/ words sentences)) (* 84.6 (/ syllables words))))) | ||
score)) |
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.
Do we need so store score
via let
if we are just returning it? Should we just return the calculation instead?
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.
Not really, I think I was doing some debugging with prints at the time. I will update that as well.
@@ -152,6 +152,12 @@ | |||
:group 'writegood | |||
:type '(repeat character)) | |||
|
|||
(defcustom writegood-on-the-fly-modes |
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'm no sure I understand why we would want to restrict the modes here?
If I turn on writegood in any mode and then toggle on the on-the-fly feature, it should work. Is there a reason to add this filtering/checking step?
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.
So far this mode acts globally when you toggle it. This means that if you are programming, writegood-mode would try to calculate the score of your code (which does not seem to make sense). For this reason I restricted to only those modes I found this feature useful.
A sensible alternative would be to run the feature only for the current buffer.
I just like it activated by default in multiple modes because I do not need to think about activating useful stuff while I am focusing on writing. Sometimes I just think: "this sentence does not look good" and then I find confirmation in the sentence score in the modeline :)
writegood-mode.el
Outdated
|
||
(defun writegood-on-the-fly-turn-on () | ||
"Add hooks to enable on-the-fly scoring." | ||
(add-hook 'post-command-hook 'writegood-after-sentence-hook) |
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 think we can probably use something like this instead:
(add-hook 'post-self-insert-hook 'syntax-check-continuous nil t)
Really, the post-self-insert-hook
is the part we want. That will take away the need to string-match the command name. We'll still need to check for a sentence 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.
This sounds interesting! I will play around with it and propose an alternative.
writegood-mode.el
Outdated
(defun writegood-after-sentence () | ||
"Calculate reading ease after a sentence is completed. Here we | ||
consider the sentence completion the addition of a dot." | ||
(if (and (string-match-p (regexp-quote "self-insert-command") (symbol-name last-command)) (eq (char-before) 46)) (writegoodmode-reading-ease-sentence))) |
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.
Is char 46 a '.'? What if a sentence ends with a question-mark? Or exclamation point!? We'll need a more general check for sentence end to apply here.
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.
You are perfectly right! I did not think about it at all.
Should I propose a set of characters that delimit a sentence or you have already a list in mind?
Maybe I can find something already done for thing-at-point 'sentence
(defun writegood-on-the-fly-turn-on () | ||
"Add hooks to enable on-the-fly scoring." | ||
(add-hook 'post-command-hook 'writegood-after-sentence-hook) | ||
(add-hook 'post-command-hook 'writegood-after-paragraph-hook) |
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 wonder if we can use fill-paragraph-function
here to avoid checking the last command and better plug into the fill architecture.
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 a very cool comment: I will both improve the code and learn more about Emacs fill architecture :D
I will give a look into this, and propose an alternative.
Thanks for the review/comments! It sounds I will learn quite a bit by acting on them. |
@bnbeckwith how is it going? I think I can work on it a bit more after Christmas if you have further feedback |
Closes #25
Looking forward to get some feedback about this :)