CaseFoldSearch

Last edit

Summary: Rückgängig gemacht auf den Stand vom 2013-08-24 11:21 UTC

Changed:

< WikiModesing case-sensitivity is governed by the variable <code>case-fold-WikiModes</code>: nil means case-sensitive; non-nil means case-insensitive (the case is "folded"). <code>case-fold-WikiModes</code> also affects how lots of programs work. For example MailSplitting in Gnus.
< The default behaviour is to make WikiModeses case insensitive, unless you are WikiModesing for a mixed case word.
< See also: IncrementalWikiModes

to

> Searching case-sensitivity is governed by the variable <code>case-fold-search</code>: nil means case-sensitive; non-nil means case-insensitive (the case is "folded"). <code>case-fold-search</code> also affects how lots of programs work. For example MailSplitting in Gnus.
> The default behaviour is to make searches case insensitive, unless you are searching for a mixed case word.
> See also: IncrementalSearch

Changed:

< == Toggle Case-Sensitivity on the Fly in IWikiModes ==
< Command `iWikiModes-toggle-case-fold' toggles case-folding in WikiModesing on and off. The tip is to bind this command to `C-s C-c', so you can toggle on the fly, while WikiModesing.

to

> == Toggle Case-Sensitivity on the Fly in Isearch ==
> Command `isearch-toggle-case-fold' toggles case-folding in searching on and off. The tip is to bind this command to `C-s C-c', so you can toggle on the fly, while searching.

Changed:

< (add-hook 'iWikiModes-mode-hook

to

> (add-hook 'isearch-mode-hook

Changed:

< (define-key iWikiModes-mode-map "\C-h" 'iWikiModes-mode-help)
< (define-key iWikiModes-mode-map "\C-t" 'iWikiModes-toggle-regexp)
< (define-key iWikiModes-mode-map "\C-c" 'iWikiModes-toggle-case-fold)
< (define-key iWikiModes-mode-map "\C-j" 'iWikiModes-edit-string))))

to

> (define-key isearch-mode-map "\C-h" 'isearch-mode-help)
> (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
> (define-key isearch-mode-map "\C-c" 'isearch-toggle-case-fold)
> (define-key isearch-mode-map "\C-j" 'isearch-edit-string))))

Changed:

< * <code>iWikiModes-mode-help</code> -- Provides help on incremental WikiModesing. Defined in library Lisp:iWikiModes+.el.
< * <code>iWikiModes-toggle-regexp</code> -- Toggles regexp WikiModesing on and off.
< * <code>iWikiModes-edit-string</code> -- Edit the WikiModes string in the MiniBuffer. This also provides other iWikiModes options, including word WikiModeses (C-w).

to

> * <code>isearch-mode-help</code> -- Provides help on incremental searching. Defined in library Lisp:isearch+.el.
> * <code>isearch-toggle-regexp</code> -- Toggles regexp searching on and off.
> * <code>isearch-edit-string</code> -- Edit the search string in the MiniBuffer. This also provides other isearch options, including word searches (C-w).

Changed:

< To indicate the current state of <code>case-fold-WikiModes</code> in your ModeLine, add the following to your ~/.emacs:

to

> To indicate the current state of <code>case-fold-search</code> in your ModeLine, add the following to your ~/.emacs:

Changed:

< Subject: Re: case-fold-WikiModes indicator

to

> Subject: Re: case-fold-search indicator

Changed:

< (add-to-list 'minor-mode-alist '(case-fold-WikiModes " CFS"))
< This then displays <tt>CFS</tt> when the WikiModesing is case-insensitive, otherwise it shows nothing.

to

> (add-to-list 'minor-mode-alist '(case-fold-search " CFS"))
> This then displays <tt>CFS</tt> when the searching is case-insensitive, otherwise it shows nothing.

Changed:

< In Lisp programs, be sure to set the case-fold-WikiModes variable to nil with regular expressions that desire to be case-sensitive. To do this in your Lisp program set the case-fold-WikiModes variable to false (nil) temporarily with the let syntax:

to

> In Lisp programs, be sure to set the case-fold-search variable to nil with regular expressions that desire to be case-sensitive. To do this in your Lisp program set the case-fold-search variable to false (nil) temporarily with the let syntax:

Changed:

< (let ((case-fold-WikiModes nil)) ;; case-sensitive!!
< (if (re-WikiModes-forward

to

> (let ((case-fold-search nil)) ;; case-sensitive!!
> (if (re-search-forward

Changed:

< expression. The regexp-builder as well as the re-WikiModes-forward was

to

> expression. The regexp-builder as well as the re-search-forward was


Searching case-sensitivity is governed by the variable case-fold-search: nil means case-sensitive; non-nil means case-insensitive (the case is “folded”). case-fold-search also affects how lots of programs work. For example MailSplitting? in Gnus.

The default behaviour is to make searches case insensitive, unless you are searching for a mixed case word.

See also: IncrementalSearch

Tips and Enhancements

Toggle Case-Sensitivity on the Fly in Isearch

Command ‘isearch-toggle-case-fold’ toggles case-folding in searching on and off. The tip is to bind this command to ‘C-s C-c’, so you can toggle on the fly, while searching.

This code does that:

  (add-hook 'isearch-mode-hook
            (function
             (lambda ()
               (define-key isearch-mode-map "\C-h" 'isearch-mode-help)
               (define-key isearch-mode-map "\C-t" 'isearch-toggle-regexp)
               (define-key isearch-mode-map "\C-c" 'isearch-toggle-case-fold)
               (define-key isearch-mode-map "\C-j" 'isearch-edit-string))))

Actually, it also adds some other ‘C-s’ bindings:

Modeline Indicator

To indicate the current state of case-fold-search in your ModeLine, add the following to your ~/.emacs:

 From: KalleOlaviNiemitalo
 Subject: Re: case-fold-search indicator
 Newsgroups: gnu.emacs.help
 Date: 21 Jun 2001 18:06:42 +0300
 (add-to-list 'minor-mode-alist '(case-fold-search " CFS"))

This then displays CFS when the searching is case-insensitive, otherwise it shows nothing.

Using Regular Expressions

In Lisp programs, be sure to set the case-fold-search variable to nil with regular expressions that desire to be case-sensitive. To do this in your Lisp program set the case-fold-search variable to false (nil) temporarily with the let syntax:

 (define mytext-find-heading ()
  "Finds text heading by finding a line whose letters are uppercase."
  (interactive)
  (message "Finding text headings ...")
  (push-mark)
  (let ((case-fold-search nil)) ;; case-sensitive!!
    (if (re-search-forward
	 "^[^a-z\n]+$" nil 'move)
	(message "Found text heading.")
      (message "End of buffer"))))

[new] The term “case-fold” might appear strange to an emacs newbie. Is there any reason, “historical” or other, for it? – PhilHudson

I’ve got the same question as PhilHudson. More precisely I’ve trapped when trying to find capitalize word in a text with regular expression. The regexp-builder as well as the re-search-forward was actually returning every single word, capitalized or not. Until I dive into the source and understood. Once known it’s ok, but IMHO it must not be the default behavior? Well … hard to change the behavior once it has been the case so much time. Too much code out there expect it to be … a feature now.


CategoryRegexp