bnbeckwith / writegood-mode

Minor mode for Emacs to improve English writing
http://bnbeckwith.com/code/writegood-mode.html
464 stars 32 forks source link

Change weasel words runtime, add user word list #9

Closed heikkil closed 9 years ago

heikkil commented 10 years ago

This patch makes it possible to modify the weasel word list and see them recognized in the text without reloading the package.

I've taken defvars writegood-weasels-font-lock-keywords-regexp and writegood-weasels-font-lock-keywords that are there only to process writegood-weasel-words list, and turned writegood-weasels-font-lock-keywords into a function that processes writegood-weasel-words and a new list writegood-more-weasel-words. The list writegood-more-weasel-words is initially empty, so user can maintain his/her own word collection.

The advantage of this is that if you want to add new weasel words, the original weasel word list need not to touched and it is easy to add new words in runtime. The performance hit caused by turning the list of weasel words into regular expression every time the mode is toggled seems to be negligible.

With these changes, it is possible to modify the user word list, e.g.

(setq writegood-more-weasel-words
      '("for the purpose of" "for the purposes of"))

and toggle on writegood-mode, to see them highlighted in the text. The main weasel word list can be modified similarly.

bnbeckwith commented 10 years ago

Hi heikkl. Thanks for the pull request.

I can see how the addition of extra words in any of the lists does not get updated automatically in the regexps. Good catch. I'll put it in the mode toggle for now like you have.

I don't quite see why we need two different lists of words. The default list (in the defcustom) can be modified by the user to append words. This would have the same effect that you are trying to achieve.

I realized with this PR that my defcustom portions were broken and in need of fixing by changing the type from 'list to '(repeat string). Am I missing something on why the addition of another variable for the words is necessary?

heikkil commented 10 years ago

I guess the writegood-mode as it is now does not really need multiple lists. I just see it cleaner to separate the official word list from additional ones that user might want to add, perhaps temporarily.

Ideally, I'd like these kind of writing help tools to have several independently controlled levels of strictness in checking. For example, separating clear errors from strong suggestions and plain English recommendations. I was exploring ways to implement highlighting different word lists, when I ran into this list update problem.

bnbeckwith commented 9 years ago

heikkil,

Thanks again for this PR. I was able to incorporate your ideas into the code today. The dynamic behavior should fix the issues you were facing.

I did decide to keep the original lists. It seems cleaner in the customize interface and not too bad from code. A user could use

(add-to-list 'writegood-weasel-words "foo")

And modify the list.

paulgigas commented 9 years ago

I am a little confused. Weasel words are important to me. "magnitude" and other words like it give me the creeps. But when I add them to cusomize group: writegood weasel words, they get sent to .emacs custom but they do not appear marked in the text. Why? I got my copy from Elpa. I recently updated but custom has the word mismatch beside the saved phrase. And still no joy. What am I doing wrong? Thanks. PS, also tried the above lisp, which didn't work.

Debian Wheezy

bnbeckwith commented 9 years ago

paulgigas,

When you use the add-to-list method, You may need to require writegood-mode first.

(require 'writegood-mode)
(add-to-list writegood-weasel-words "magnitude")

As for setting through custom -- that method should work well. The clue is that the custom prompt says that you have a mismatch on the type you are saving. This code section was updated in the last half year to be correct and it seems it caught you in the middle.

Try this:

  1. Customize writegood-weasel-words
  2. Click on "State" -> "Erase Customization"
  3. Enter in your new word(s)
  4. Save your customizations

Also, feel free to open an issue if this does not fix your issues. Thanks for the feedback.