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

Add on-the-fly easy score checking #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ag91
Copy link

@ag91 ag91 commented Dec 4, 2018

Closes #25

Looking forward to get some feedback about this :)

@ag91
Copy link
Author

ag91 commented Dec 4, 2018

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.

@bnbeckwith
Copy link
Owner

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.

@robstewart57
Copy link

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.

@ag91
Copy link
Author

ag91 commented Dec 5, 2018

@robstewart57 that makes perfect sense! Too functional oriented XD I will update with that change

@ag91
Copy link
Author

ag91 commented Dec 5, 2018 via email

Copy link
Owner

@bnbeckwith bnbeckwith left a 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.

;;;###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
Copy link
Owner

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?

Copy link
Author

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.

(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))
Copy link
Owner

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?

Copy link
Author

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
Copy link
Owner

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?

Copy link
Author

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 :)


(defun writegood-on-the-fly-turn-on ()
"Add hooks to enable on-the-fly scoring."
(add-hook 'post-command-hook 'writegood-after-sentence-hook)
Copy link
Owner

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.

Copy link
Author

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.

(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)))
Copy link
Owner

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.

Copy link
Author

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)
Copy link
Owner

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.

Copy link
Author

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.

@ag91
Copy link
Author

ag91 commented Dec 7, 2018

Thanks for the review/comments! It sounds I will learn quite a bit by acting on them.
Very welcomed!

@ag91
Copy link
Author

ag91 commented Dec 17, 2018

@bnbeckwith how is it going? I think I can work on it a bit more after Christmas if you have further feedback

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

Successfully merging this pull request may close these issues.

3 participants