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

How to disable searching in invisible text? (setq search-invisible nil) has no effect #1739

Closed
QiangF opened this issue Sep 4, 2018 · 9 comments

Comments

@QiangF
Copy link

@QiangF QiangF commented Sep 4, 2018

No description provided.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Sep 9, 2018

Please give a use case of a buffer with half-invisible / half-visible text.

@QiangF
Copy link
Author

@QiangF QiangF commented Sep 10, 2018

I want to search for function names after outline-hide-sublevels. Also you can serach in org headings.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Sep 13, 2018

I don't think it's essential for swiper to have this feature.

There are better ways for getting completion for function names or outline headings, like e.g. counsel-imenu or counsel-semantic.

@QiangF
Copy link
Author

@QiangF QiangF commented Sep 17, 2018

The problem with counsel is that it uses the minibuffer, too small if the file is large, it always helps if you can see more.

@QiangF
Copy link
Author

@QiangF QiangF commented Sep 17, 2018

And there's more functions you can use in a folded buffer than in the counsel minibuffer. Moreover isearch has this functionality.

@QiangF
Copy link
Author

@QiangF QiangF commented Jun 16, 2019

It's can also be used in folded outline buffer (headings). The following enables outline for all program mode.

(defun my-heading()
"custom heading for all prog mode"
(when (and (not (equal major-mode 'org-mode)) comment-start)
  (make-local-variable 'my-outline-regexp)
  (make-local-variable 'my-outline-max-level)
  (setq my-outline-max-level 8)
  (setq my-outline-regexp (concat (regexp-quote comment-start) " [*]\\{1,8\\}"))
  (setq outline-heading-alist '()) ;; make outline promote work
  (let ((level 0)
    (level-prefix (concat comment-start " ")))
    (while (< level my-outline-max-level)
    (setq outline-heading-alist (cons (cons level-prefix level) outline-heading-alist)
    level (1+ level)
    level-prefix (concat level-prefix "*")))
    (setq outline-heading-alist (nreverse outline-heading-alist)))
  (setq outline-regexp (concat my-outline-regexp "\\|" outline-regexp)
    outline-level (lambda()
     (let* ((data (match-data))
       (start (car data))
       (end (cadr data))
       (level (- end start)))
       (if (looking-at my-outline-regexp)
       (- level 2) ;; subtract two spaces
       (+ level my-outline-max-level));; 8 is the maximum custom heading levels)))))
(add-hook 'outline-minor-mode-hook 'my-heading)

swiper will be much better than isearch

(defun jmm/isearch-forward-visible ()
"Just `isearch-forward` but don't match invisible text."
(interactive)
(let ((search-invisible nil))
    (isearch-forward)))

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jun 25, 2019

Sorry, it's still not clear for me. I can't get your code to work.

@QiangF
Copy link
Author

@QiangF QiangF commented Jun 26, 2019

It just customizes the outline regexp for heading, so for elisp mode you have heading like:

; * heading level 1
; ** heading level 2

for python mode it is:

#  * heading level 1:
#  * heading level 2:

If search-invisible is enabled, we can fold the outline and easily search in those headings.

@abo-abo abo-abo closed this in d260c48 Jun 27, 2019
@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jun 27, 2019

Thanks, please test.

astoff added a commit to astoff/swiper that referenced this issue Jan 1, 2021
When `search-invisible' is nil, `swiper' and `swiper-isearch' will not
match hidden text (e.g. hidden Org outlines).

Fixes abo-abo#1739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants