all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: wrap-search 2.1.4
Date: Thu, 02 Jun 2022 03:30:18 +0200	[thread overview]
Message-ID: <87fsknn979.fsf@dataswamp.org> (raw)

New version of this program that I used more times (I think)
than every other program I ever wrote, combined. (It says its
from 2021-05-23, that refers to the package tho, actually it's
10~15yo.)

In 2.1.4, it does regions as well.

Will there ever be another version? I don't know, maybe 3D
search is a feature that's lacking?

;;; wrap-search.el --- wrapped, non-incremental search -*- lexical-binding: t -*-
;;
;;; Commentary:
;;
;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;; Created: 2021-05-23
;; Keywords: matching
;; License: GPL3+
;; Package-Requires: ((cl-lib "1.0"))
;; URL: https://dataswamp.org/~incal/emacs-init/wrap-search.el
;; Version: 2.1.4
;;
;; The `wrap-search' package offers non-incremental, search -
;; it shows hitss (hits and only hits).
;;
;; `wrap-search' searches forward by default, but it wraps
;; and continues up and until the search start position if
;; necessary. This is so one doesn't have to wonder if the
;; target is north or south in the buffer.
;;
;; The philosophy is that `wrap-search' mostly shouldn't be
;; used for searching - which is possible as well, of course,
;; using the same commands - rather, it is used to quickly
;; _navigate_ a buffer.
;;
;; To use the package without keyboard shortcuts isn't
;; recommended. Instead, do for example
;;
;;   (global-set-key "\C-s" #'wrap-search)
;;   (global-set-key "\C-r" #'wrap-search-again)
;;
;;; Code:

(require 'cl-lib)

(defun wrap-search-again ()
  "Repeat the previous `wrap-search'.

Do a new `wrap-search' with \\[wrap-search]"
  (interactive)
  (let ((cmd (cl-find-if (lambda (c)
                           (and (eq (car c) #'wrap-search)
                                (not (string= (nth 1 c) "")) ))
                         command-history) ))
    (if cmd
        (eval cmd)
      (message "no previous search") )))

(defun wrap-search (str &optional case rev beg end)
  "Search for STR.

With CASE the search is case-sensitive.
With REV the search direction is reversed, i.e. north in the buffer from point.
BEG and END, or a region, delimits the search area. (default: whole buffer)

Interactively, \\[universal-argument] once sets CASE
\\[universal-argument] twice sets REV
\\[universal-argument] thrice sets CASE and REV.

Do \\[wrap-search-again] to repeat, with `wrap-search-again'."
  (interactive
   (list (read-string "search: [repeat] ")
         (or (equal current-prefix-arg '( 4))
             (equal current-prefix-arg '(64)) )
         (or (equal current-prefix-arg '(16))
             (equal current-prefix-arg '(64)) )
         (if (use-region-p)
             (region-beginning)
           (point-min) )
         (if (use-region-p)
             (region-end)
           (point-max) )))
  (if (string= "" str)
      (wrap-search-again)
    (let*((case-fold-search (not case))
          (pos (point))
          (search-f (if rev
                        #'search-backward
                      #'search-forward) )
          (search-beg (if rev
                          end
                        beg) )
          (search-end (if rev
                          beg
                        end) ))
      (if (apply (list search-f str search-end t))
          (message "hit: %s" (point))
        (goto-char search-beg)
        (if (apply (list search-f str (+ pos (if rev 0 (length str))) t))
            (if (= pos (point))
                (message "this is the one occurrence")
              (message "hit: %s (wrap)" (point)))
          (goto-char pos)
          (message "no hit") )))))

(provide 'wrap-search)
;;; wrap-search.el ends here

-- 
underground experts united
https://dataswamp.org/~incal




                 reply	other threads:[~2022-06-02  1:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsknn979.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.