@ -40,8 +40,7 @@ If there's a string at point, offer that as a default."
" Using `search-function' , execute the search "
( interactive )
( kill-buffer macoy-select-search-buf-name )
( apply search-function macoy-select-search-search after-search-args )
)
( apply search-function macoy-select-search-search after-search-args ) )
;; TODO: Make generic system (e.g. refresh cache selector)
( setq macoy-select-search-key-descriptions " Select search:
@ -57,28 +56,28 @@ If there's a string at point, offer that as a default."
( defvar macoy-select-search-minor-mode-map
( let ( ( map ( make-sparse-keymap ) ) )
;; Ag with default directory
( define-key map ( kbd " a " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'ag default-directory ) ) )
;; Ag with browse directory
( define-key map ( kbd " b " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'ag ( read-directory-name " Directory: " ) ) ) )
;; Ag with project filter
( define-key map ( kbd " f " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'macoy-ag-with-project-filter ( read-directory-name " Directory: " ) ) ) )
;; Codesearch source with filter (directory defined by `codesearch-dir-to-index', aka use ~/.csearchindex)
( define-key map ( kbd " c " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'macoy-codesearch-search-src ) ) )
;; Codesearch data
( define-key map ( kbd " d " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'macoy-codesearch-search-with-filter-directory macoy-codesearch-search-data-dir ) ) )
;; Swiper all
( define-key map ( kbd " s " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'swiper-all ) ) )
;; Internet search
( define-key map ( kbd " i " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'engine/search-duckduckgo ) ) )
( define-key map ( kbd " q " ) ( lambda ( ) ( interactive ) ( kill-buffer macoy-select-search-buf-name ) ) )
( define-key map ( kbd " a " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'ag default-directory ) ) )
;; Ag with browse directory
( define-key map ( kbd " b " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'ag ( read-directory-name " Directory: " ) ) ) )
;; Ag with project filter
( define-key map ( kbd " f " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'macoy-ag-with-project-filter ( read-directory-name " Directory: " ) ) ) )
;; Codesearch source with filter (directory defined by `codesearch-dir-to-index', aka use ~/.csearchindex)
( define-key map ( kbd " c " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'macoy-codesearch-search-src ) ) )
;; Codesearch data
( define-key map ( kbd " d " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'macoy-codesearch-search-with-filter-directory macoy-codesearch-search-data-dir ) ) )
;; Swiper all
( define-key map ( kbd " s " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'swiper-all ) ) )
;; Internet search
( define-key map ( kbd " i " ) ( lambda ( ) ( interactive ) ( macoy-select-do-search
'engine/search-duckduckgo ) ) )
( define-key map ( kbd " q " ) ( lambda ( ) ( interactive ) ( kill-buffer macoy-select-search-buf-name ) ) )
map )
" macoy-select-search-minor-mode keymap. " )
@ -91,25 +90,24 @@ If there's a string at point, offer that as a default."
( interactive ( list ( macoy-read-from-minibuffer " Search string " ) ) )
;; Only search if search string
( when string
;; Hang on to the search string
( setq macoy-select-search-search string )
;; Create a buffer `macoy-select-search-buf-name'
( get-buffer-create macoy-select-search-buf-name )
;; Switch to the `macoy-select-search-buf-name' buffer
;; (switch-to-buffer-other-window macoy-select-search-buf-name)
( switch-to-buffer macoy-select-search-buf-name )
( insert macoy-select-search-key-descriptions )
;; Set its major mode to `special-mode'
( special-mode ) ; a read-only major mode
;; As you are now in the `macoy-select-search-buf-name' buffer, you can do the below:
;; - hit `q' to quit the current window *without* killing `macoy-select-search-buf-name'
;; - hit `C-u q' to quit the current window *and* kill `macoy-select-search-buf-name'
( macoy-select-search-minor-mode 1 )
) )
;; Hang on to the search string
( setq macoy-select-search-search string )
;; Create a buffer `macoy-select-search-buf-name'
( get-buffer-create macoy-select-search-buf-name )
;; Switch to the `macoy-select-search-buf-name' buffer
;; (switch-to-buffer-other-window macoy-select-search-buf-name)
( switch-to-buffer macoy-select-search-buf-name )
( insert macoy-select-search-key-descriptions )
;; Set its major mode to `special-mode'
( special-mode ) ; a read-only major mode
;; As you are now in the `macoy-select-search-buf-name' buffer, you can do the below:
;; - hit `q' to quit the current window *without* killing `macoy-select-search-buf-name'
;; - hit `C-u q' to quit the current window *and* kill `macoy-select-search-buf-name'
( macoy-select-search-minor-mode 1 ) ) )
( global-set-key ( kbd " C-e " ) 'macoy-select-search )
@ -122,18 +120,15 @@ If there's a string at point, offer that as a default."
" Conditionally filter ag results based on whether I know I should filter certain files (i.e. I'm in a project) "
( interactive )
( if ( projectile-project-p )
( setq ag-arguments ' ( " --smart-case " " --stats " " -G "
" ( \\ .txt| \\ .org| \\ .cpp| \\ .c| \\ .h| \\ .inl| \\ .html| \\ .css| \\ .lua| \\ .js| \\ .py| \\ .cdm| \\ .el) "
" --ignore " " AutoGen " ) )
( setq ag-arguments ' ( " --smart-case " " --stats " ) )
)
( setq ag-arguments ' ( " --smart-case " " --stats " " -G "
" ( \\ .txt| \\ .org| \\ .cpp| \\ .c| \\ .h| \\ .inl| \\ .html| \\ .css| \\ .lua| \\ .js| \\ .py| \\ .cdm| \\ .el) "
" --ignore " " AutoGen " ) )
( setq ag-arguments ' ( " --smart-case " " --stats " ) ) )
( if ( and pattern directory )
( ag pattern directory )
( call-interactively 'ag )
)
( ag pattern directory )
( call-interactively 'ag ) )
;; Reset the arguments so we don't unintentionally have a filter
( setq ag-arguments ' ( " --smart-case " " --stats " ) )
)
( setq ag-arguments ' ( " --smart-case " " --stats " ) ) )
;; (global-set-key (kbd "C-M-f") 'macoy-ag-with-project-filter)
;; (global-set-key (kbd "C-M-F") 'ag)
@ -148,7 +143,7 @@ If there's a string at point, offer that as a default."
;;
;; Always rescan all folders when indexing
( if codesearch-filter-supported
( setq codesearch-cindex-args ( list " -reset " " -exclude " " f:/CJUNCTIONS/src/csearchIgnorePatterns " ) )
( setq codesearch-cindex-args ( list " -reset " " -exclude " " f:/CJUNCTIONS/src/csearchIgnorePatterns " ) )
;; Use if junkblocker codesearch fork is not used
( setq codesearch-cindex-args ( list " -reset " ) ) )
@ -158,19 +153,19 @@ If there's a string at point, offer that as a default."
( setq codesearch-csearch-exe " c:/Users/mmadson/go/bin/csearch.exe " )
( setq codesearch-cindex-exe " c:/Users/mmadson/go/bin/cindex.exe " )
( setq codesearch-dir-to-index " f:/CJUNCTIONS/src " )
( setq codesearch-index-file " ~/.csearchindex " )
( setq codesearch-temp-file " c:/.temp-codesearch.txt " )
;; (setq macoy-codesearch-search-data-dir "D:/Magic/data")
)
( setq codesearch-temp-file " c:/.temp-codesearch.txt " ) )
;; (setq macoy-codesearch-search-data-dir "D:/Magic/data"))
( when ( string-equal ( user-login-name ) " macoy " )
( setq codesearch-csearch-exe " csearch " )
( setq codesearch-cindex-exe " cindex " )
( setq codesearch-dir-to-index " /home/macoy/Development/code/repositories " )
( setq codesearch-index-file " ~/.csearchindex " )
( setq codesearch-temp-file " ~/.temp-codesearch.txt " )
( setq macoy-codesearch-search-data-dir nil )
)
( setq macoy-codesearch-search-data-dir nil ) )
;; Make it possible to index multiple directories at the same time
( defun macoy-codesearch-name-function ( name-of-mode )
( format " *Codesearch index* %s " compilation-environment ) )
;; TODO: Rename compilation buffer and add a finished message?
( defun macoy-codesearch-index-directory ( directory )
@ -178,11 +173,12 @@ If there's a string at point, offer that as a default."
( interactive )
( message " Running Codesearch index on %s " directory )
( set ( make-local-variable 'compilation-environment )
( list ( format " %s%s%s " " CSEARCHINDEX= " directory " /.csearchindex " ) ) )
( compile ( string-join
( append ( list codesearch-cindex-exe )
codesearch-cindex-args
( list directory ) ) " " ) ) )
( list ( format " %s%s%s " " CSEARCHINDEX= " directory " /.csearchindex " ) ) )
( let ( ( compilation-buffer-name-function 'macoy-codesearch-name-function ) )
( compile ( string-join
( append ( list codesearch-cindex-exe )
codesearch-cindex-args
( list directory ) ) " " ) ) ) )
( defun macoy-codesearch-index-default ( )
( interactive )
@ -191,19 +187,16 @@ If there's a string at point, offer that as a default."
;; This is okay too because having an existing index doesn't speed things up all that much
;; Commented because this is no longer needed due to using -reset
;; (when (file-exists-p codesearch-index-file)
;; (delete-file codesearch-index-file)
;; )
;; (delete-file codesearch-index-file))
;; We won't use this way for now so that we can run two indexes at the same time
;; (macoy-codesearch-index-directory codesearch-dir-to-index)
( let ( ( codesearch-proc ( apply 'start-process
( append ( list " CodesearchIndex " " *Codesearch-Index* " codesearch-cindex-exe )
codesearch-cindex-args
( list codesearch-dir-to-index ) ) ) ) )
( set-process-sentinel codesearch-proc
( lambda ( codesearch-proc _string )
( message " Codesearch finished building index " ) ) )
)
)
( macoy-codesearch-index-directory codesearch-dir-to-index ) )
;; (let ((codesearch-proc (apply 'start-process
;; (append (list "CodesearchIndex" "*Codesearch-Index*" codesearch-cindex-exe)
;; codesearch-cindex-args
;; (list codesearch-dir-to-index)))))
;; (set-process-sentinel codesearch-proc
;; (lambda (codesearch-proc _string)
;; (message "Codesearch finished building index")))))
;; TODO: There is no way to undo after doing this; you have to repeat the search
( defun macoy-filter-buffer ( )
@ -214,15 +207,13 @@ If there's a string at point, offer that as a default."
( read-only-mode 0 )
( call-interactively 'keep-lines )
;; Start with the cursor on the first result
( compilation-next-error 1 )
)
( compilation-next-error 1 ) )
;; Refer to ag.el for customization
( define-compilation-mode macoy-codesearch-mode " Codesearch "
" Codesearch results compilation mode "
;; This is so you can delete results with C-S-k. This doesn't break n and p which is cool
( read-only-mode 0 )
)
( read-only-mode 0 ) )
( define-key macoy-codesearch-mode-map ( kbd " p " ) #' compilation-previous-error )
( define-key macoy-codesearch-mode-map ( kbd " n " ) #' compilation-next-error )
@ -241,34 +232,30 @@ If there's a string at point, offer that as a default."
;; Args explanation: -n (Line numbers) -i (ignore case)
;; Output Codesearch results to a temporary file, filter out lines, then clean up the temp file
( if directory
( set ( make-local-variable 'compilation-environment ) ( list ( format " %s%s%s " " CSEARCHINDEX= " directory " /.csearchindex " ) ) )
( set ( make-local-variable 'compilation-environment ) nil )
)
( set ( make-local-variable 'compilation-environment ) ( list ( format " %s%s%s " " CSEARCHINDEX= " directory " /.csearchindex " ) ) )
( set ( make-local-variable 'compilation-environment ) nil ) )
( if codesearch-filter-supported
( compilation-start ( format " %s -n -i \" %s \" "
codesearch-csearch-exe
;; (regexp-quote pattern) ;; This doesn't work because more escape(\) chars are added
pattern )
#' macoy-codesearch-mode
` ( lambda ( mode-name ) , " *Codesearch* " )
)
;; This temp-file thing sucks but seems necessary for Windows
( compilation-start ( format " %s -n -i \" %s \" > %s && grep -i -E -v \" %s \" %s && rm %s "
codesearch-csearch-exe
;; (regexp-quote pattern) ;; This doesn't work because more escape(\) chars are added
pattern
codesearch-temp-file
macoy-codesearch-ignore-lines-pattern
codesearch-temp-file
codesearch-temp-file )
#' macoy-codesearch-mode
` ( lambda ( mode-name ) , " *Codesearch* " )
) ) )
( compilation-start ( format " %s -n -i \" %s \" "
codesearch-csearch-exe
;; (regexp-quote pattern) ;; This doesn't work because more escape(\) chars are added
pattern )
#' macoy-codesearch-mode
` ( lambda ( mode-name ) , " *Codesearch* " ) )
;; This temp-file thing sucks but seems necessary for Windows
( compilation-start ( format " %s -n -i \" %s \" > %s && grep -i -E -v \" %s \" %s && rm %s "
codesearch-csearch-exe
;; (regexp-quote pattern) ;; This doesn't work because more escape(\) chars are added
pattern
codesearch-temp-file
macoy-codesearch-ignore-lines-pattern
codesearch-temp-file
codesearch-temp-file )
#' macoy-codesearch-mode
` ( lambda ( mode-name ) , " *Codesearch* " ) ) ) )
( defun macoy-codesearch-search-src ( pattern )
( interactive ( list ( macoy-read-from-minibuffer " Search string " ) ) )
( macoy-codesearch-search-with-filter-directory pattern nil )
)
( macoy-codesearch-search-with-filter-directory pattern codesearch-dir-to-index ) )
( global-set-key ( kbd " C-S-f " ) 'macoy-codesearch-search-src )
@ -276,8 +263,8 @@ If there's a string at point, offer that as a default."
( defun macoy-isearch-yank-clipboard ( )
" Insert the contents of the clipboard into isearch. We do this because we don't use the yank stuff "
( interactive )
( isearch-yank-string ( simpleclip-get-contents ) )
)
( isearch-yank-string ( simpleclip-get-contents ) ) )
( define-key isearch-mode-map ( kbd " C-v " ) 'macoy-isearch-yank-clipboard )
;; Go to next/previous result with arrow keys
( define-key isearch-mode-map ( kbd " <up> " ) 'isearch-repeat-backward )
@ -293,16 +280,14 @@ If there's a string at point, offer that as a default."
;; End the search
( isearch-done )
;; Select the results list buffer
( switch-to-buffer-other-window " *Occur* " )
)
( switch-to-buffer-other-window " *Occur* " ) )
( define-key isearch-mode-map ( kbd " C-a " ) 'macoy-isearch-occur )
;; We're going to use smooth scrolling only for isearch so there's a good margin between a search
;; result which would've ended up at the very bottom of the window without smooth scrolling
( require 'smooth-scrolling )
( defun macoy-isearch-end-hook ( )
( smooth-scrolling-mode 0 )
)
( smooth-scrolling-mode 0 ) )
( setq isearch-mode-end-hook 'macoy-isearch-end-hook )
;; If marked, use swiper to search mark
@ -315,48 +300,44 @@ If there's a string at point, offer that as a default."
( call-interactively 'isearch-forward )
( when ( use-region-p )
;; (isearch-search)
;; (call-interactively 'isearch-forward)
( isearch-yank-string ( buffer-substring ( region-beginning ) ( region-end ) ) )
;; Clear the mark for two reasons:
;; 1. Occur will only search the region, but whenever I use occur I expect
;; it to show me all results in the entire file
;; 2. I don't like how it looks visually when the mark is expanding while I'm going
;; through results.
;; I never use isearch to change my region, so this seemed like an acceptable tradeoff
( setq mark-active nil )
)
)
;; (isearch-search)
;; (call-interactively 'isearch-forward)
( isearch-yank-string ( buffer-substring ( region-beginning ) ( region-end ) ) )
;; Clear the mark for two reasons:
;; 1. Occur will only search the region, but whenever I use occur I expect
;; it to show me all results in the entire file
;; 2. I don't like how it looks visually when the mark is expanding while I'm going
;; through results.
;; I never use isearch to change my region, so this seemed like an acceptable tradeoff
( setq mark-active nil ) ) )
( global-set-key ( kbd " C-f " ) 'macoy-isearch-search-mark )
;; Swiper customizations
( when ( require 'swiper )
;; If marked, use swiper to search mark
( defun macoy-swiper-search-mark ( )
" If marked, use swiper to search mark. Otherwise, open swiper normally "
( interactive )
;; This isn't sufficient for my purposes; it's nice to search e.g. thing->thing
;;(swiper (thing-at-point 'symbol))
( if ( use-region-p )
( swiper ( buffer-substring ( region-beginning ) ( region-end ) ) )
( swiper )
) )
;; If marked, use swiper to search mark
( defun macoy-swiper-all-search-mark ( )
" If marked, use swiper-all to search mark. Otherwise, open swiper-all normally "
( interactive )
;; This isn't sufficient for my purposes; it's nice to search e.g. thing->thing
;;(swiper (thing-at-point 'symbol))
( if ( use-region-p )
( swiper-all ( buffer-substring ( region-beginning ) ( region-end ) ) )
( swiper-all )
) )
;; Use swiper for search instead of isearch (use e.g. space to fuzzy search)
;; (global-set-key (kbd "C-f") 'macoy-swiper-search-mark)
( global-set-key ( kbd " M-f " ) 'macoy-swiper-all-search-mark )
)
;; (when (require 'swiper)
;; ;; If marked, use swiper to search mark
;; (defun macoy-swiper-search-mark ()
;; "If marked, use swiper to search mark. Otherwise, open swiper normally"
;; (interactive)
;; ;; This isn't sufficient for my purposes; it's nice to search e.g. thing->thing
;; ;;(swiper (thing-at-point 'symbol))
;; (if (use-region-p)
;; (swiper (buffer-substring (region-beginning) (region-end)))
;; (swiper)))
;; ;; If marked, use swiper to search mark
;; (defun macoy-swiper-all-search-mark ()
;; "If marked, use swiper-all to search mark. Otherwise, open swiper-all normally"
;; (interactive)
;; ;; This isn't sufficient for my purposes; it's nice to search e.g. thing->thing
;; ;;(swiper (thing-at-point 'symbol))
;; (if (use-region-p)
;; (swiper-all (buffer-substring (region-beginning) (region-end)))
;; (swiper-all)))
;; ;; Use swiper for search instead of isearch (use e.g. space to fuzzy search)
;; ;; (global-set-key (kbd "C-f") 'macoy-swiper-search-mark)
;; (global-set-key (kbd "M-f") 'macoy-swiper-all-search-mark))
;; Quickly search the web
;; See https://github.com/hrs/engine-mode for more browsers
@ -364,8 +345,7 @@ If there's a string at point, offer that as a default."
;; (engine-mode t)
( defengine duckduckgo
" https://duckduckgo.com/?q=%s "
:keybinding " d " )
" https://duckduckgo.com/?q=%s "
:keybinding " d " )
( global-set-key ( kbd " M-l " ) 'engine/search-duckduckgo )
)
( global-set-key ( kbd " M-l " ) 'engine/search-duckduckgo ) )