sqlup-mode.el icon indicating copy to clipboard operation
sqlup-mode.el copied to clipboard

Use case-fold-search to simplify logic?

Open Trevoke opened this issue 8 years ago • 4 comments

case-fold-search is a variable defined in `C source code'. Its value is t

Automatically becomes buffer-local when set.

Documentation: Non-nil if searches and matches should ignore case.

You can customize this variable.

If we always go to the cloned buffer for logic, then we can make this change without messing with the users' settings.

Any thoughts on this?

Trevoke avatar Sep 12 '16 01:09 Trevoke

I think if we wanted to use case-fold-search the idiomatic and IMO correct thing to do would be to let-bind it around the function call. But I don't think it's worth it anyway: either let-binding or with-current-buffer is more complex than a call to downcase.

If you want to get rid of the scattered downcases it might be good to move them inside the various helper functions, i.e. move the downcase inside sqlup-get-redis-keywords, sqlup-keyword-p and sqlup-blacklisted-p.

davidshepherd7 avatar Sep 13 '16 06:09 davidshepherd7

I reorganized the logic around a little, and I'm not sure the way it exists makes COMPLETE sense. we're doing some keyword checks in the main buffer and some logic in the cloned buffer. I'm tempted to move all the checking to the clone buffer.

I noticed that here: https://github.com/Trevoke/sqlup-mode.el/blob/master/sqlup-mode.el#L152 because I was trying to find a way to make those function calls, in the next function, more homogeneous. Some use (point) and some use a symbol and/or symbol boundaries.

Trevoke avatar Sep 13 '16 14:09 Trevoke

Ah yeah I see what you mean. I would probably try to use the cloned buffer as little as possible though, because it's likely to be confusing to anyone trying to read/copy/modify the code (since it's sort of like a global variable).

davidshepherd7 avatar Sep 14 '16 20:09 davidshepherd7

The thing is, we do three things:

  1. Check if it's blacklisted (customizable)
  2. Check if it's a keyword (depends on SQL dialect)
  3. Check if it's capitalizable (depends on buffer environment)

1 depends on users, but 2 and 3 might as well be cloned-buffer-centric, don't you think?

Trevoke avatar Sep 15 '16 15:09 Trevoke