Browse Source

More searches to select, created build systems

* Added several more search methods to the macoy-select-search system
* Make sure ag resets its filters so that you can search with no file
  types filter
* Make it possible to have multiple different Codesearch indices which
  can be searched independently. This is awesome because I have code
  and data which should always be searched separately, but are both enormous
* Added macoy-filter-buffer for easily filtering searches
* Added build system manager. This is similar to Sublime where you can
  select from a list of different "build systems" (simply functions
  which likely just use compile) then easily rebuild the previously
  selected one
* Fixed window border colors
* Dired should now try to reuse the same buffer when visiting folders
  instead of opening a ton of buffers
master
macoymadson@gmail.com 4 years ago
parent
commit
a66970de79
  1. 192
      Emacs/emacsConfig.txt

192
Emacs/emacsConfig.txt

@ -121,6 +121,7 @@
;; C-h b to list all bindings (should've used this more when fighting binds...)
;; C-q = quoted-insert "insert the next character, whatever it is" e.g. useful for inserting a tab
;; describe-char with cursor over character will say where the font face came from (useful for theming)
;; Use ibuffer to select and kill many buffers. kill-some-buffers is also okay
;; BAD THING
;;
@ -557,16 +558,21 @@ If there's a string at point, offer that as a default."
(defun macoy-select-do-search (search-function &rest after-search-args)
"Using `search-function', execute the search"
(interactive)
(message default-directory)
(kill-buffer macoy-select-search-buf-name)
(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:
\ta - Ag (in same directory as file)
\tb - Ag (browse for directory)
\tc - Codesearch (with filter)")
\ta - Ag (in same directory as file, no filter)
\tb - Ag (browse for directory, no filter)
\tf - Ag (browse for directory, with project filter)
\tc - Codesearch (with filter)
\td - Codesearch Data (with filter)
\ts - Swiper search all buffers
\ti - Internet search (DuckDuckGo)")
;; TODO: Add ag no filter and ag filter
(defvar macoy-select-search-minor-mode-map
(let ((map (make-sparse-keymap)))
;; Ag with default directory
@ -575,9 +581,21 @@ If there's a string at point, offer that as a default."
;; Ag with browse directory
(define-key map (kbd "b") (lambda () (interactive) (macoy-select-do-search
'ag (read-directory-name "Directory: "))))
;; Codesearch with filter
;; Agg 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-with-filter)))
'macoy-codesearch-search-src)))
;; Codesearch data
(define-key map (kbd "d") (lambda () (interactive) (macoy-select-do-search
'macoy-codesearch-search-with-filter-directory "C:/Magic/data")))
;; 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)))
map)
"macoy-select-search-minor-mode keymap.")
@ -610,12 +628,14 @@ If there's a string at point, offer that as a default."
(macoy-select-search-minor-mode 1)
))
(global-set-key (kbd "C-M-f") 'macoy-select-search)
;; Searching in files (Ag)
;; Make ag.el reuse the same *ag* buffer for all your searches:
(setq ag-reuse-buffers 't)
(setq ag-arguments '("--smart-case" "--stats"))
(defun macoy-ag-with-project-filter ()
(defun macoy-ag-with-project-filter (&optional pattern directory)
"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)
@ -624,10 +644,15 @@ If there's a string at point, offer that as a default."
"--ignore" "AutoGen"))
(setq ag-arguments '("--smart-case" "--stats"))
)
(call-interactively 'ag)
(if (and pattern directory)
(ag pattern directory)
(call-interactively 'ag)
)
;; Reset the arguments so we don't unintentionally have a filter
(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") 'macoy-ag-with-project-filter)
;; (global-set-key (kbd "C-M-F") 'ag)
;; Codesearch: Use a pregenerated index to search files. Requires Codesearch
@ -650,7 +675,17 @@ If there's a string at point, offer that as a default."
(setq codesearch-index-file "~/.csearchindex")
)
(defun macoy-codesearch-index-src ()
;; TODO: Rename compilation buffer and add a finished message?
(defun macoy-codesearch-index-directory (directory)
"Create a .csearchindex for the specified directory"
(interactive)
(message "Running Codesearch index on %s" directory)
(set (make-local-variable 'compilation-environment)
(list (format "%s%s%s" "CSEARCHINDEX=" directory "/.csearchindex")))
(compile (format "%s %s %s" codesearch-cindex-exe codesearch-cindex-args directory))
)
(defun macoy-codesearch-index-default ()
(interactive)
(message "Running Codesearch index on %s" codesearch-dir-to-index)
;; Remove the old codesearch because for some reason it doesn't actually update
@ -659,26 +694,60 @@ If there's a string at point, offer that as a default."
;; (when (file-exists-p 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 (start-process "CodesearchIndex" "*Codesearch-Index*" codesearch-cindex-exe codesearch-cindex-args codesearch-dir-to-index)))
(set-process-sentinel codesearch-proc
(lambda (codesearch-proc _string)
(message "Codesearch finished building 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 ()
"Disable readonly and filter lines using keep-lines"
(interactive)
;; Make sure we get all lines by going to the start of the buffer
(goto-char (point-min))
(read-only-mode 0)
(call-interactively 'keep-lines)
;; Start with the cursor on the first result
(compilation-next-error 1)
)
;; TODO: Make n and p keys for macoy-codesearch-mode if this ever becomes a package
;; Refer to ag.el for customization
(define-compilation-mode macoy-codesearch-mode "Codesearch"
"Codesearch results compilation mode"
)
(define-key macoy-codesearch-mode-map (kbd "p") #'compilation-previous-error)
(define-key macoy-codesearch-mode-map (kbd "n") #'compilation-next-error)
(define-key macoy-codesearch-mode-map (kbd "f") 'macoy-filter-buffer)
;; The filter which will apply to codesearch results. Things matching this regex will be removed
;; This is useful for e.g. filtering autogenerated code files
;; Note that this will also remove code lines which match this pattern, so make the regex robust to that
(setq macoy-codesearch-ignore-lines-pattern "_ast\.")
;; This should work but doesn't :( (note that you may need to add -E below)
;; (setq macoy-codesearch-ignore-lines-pattern "'_ast\.|autogen'")
(defun macoy-codesearch-search-with-filter (pattern)
;; (defun macoy-codesearch-search-with-filter (pattern)
;; (interactive
;; (list
;; (read-string "Search: " (thing-at-point 'symbol))))
;; ;; Use the compile command so we have nice clickable links
;; ;; Note that without regexp-quote, this does support regexes. I don't want them in my case
;; ;; Args explanation: -n (Line numbers) -i (ignore case)
;; ;; Output Codesearch results to a temporary file, filter out lines, then clean up the temp file
;; (compilation-start (format "%s -n -i %s > .temp-codesearch.txt && grep -v %s .temp-codesearch.txt && rm .temp-codesearch.txt"
;; codesearch-csearch-exe
;; (regexp-quote pattern)
;; macoy-codesearch-ignore-lines-pattern)
;; #'macoy-codesearch-mode
;; `(lambda (mode-name) , "*Codesearch*")
;; )
;; )
(defun macoy-codesearch-search-with-filter-directory (pattern directory)
(interactive
(list
(read-string "Search: " (thing-at-point 'symbol))))
@ -686,6 +755,10 @@ If there's a string at point, offer that as a default."
;; Note that without regexp-quote, this does support regexes. I don't want them in my case
;; 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)
)
(compilation-start (format "%s -n -i %s > .temp-codesearch.txt && grep -v %s .temp-codesearch.txt && rm .temp-codesearch.txt"
codesearch-csearch-exe
(regexp-quote pattern)
@ -695,7 +768,14 @@ If there's a string at point, offer that as a default."
)
)
(global-set-key (kbd "C-S-f") 'macoy-codesearch-search-with-filter)
(defun macoy-codesearch-search-src (pattern)
(interactive
(list
(read-string "Search: " (thing-at-point 'symbol))))
(macoy-codesearch-search-with-filter-directory pattern nil)
)
(global-set-key (kbd "C-S-f") 'macoy-codesearch-search-src)
;;
;;
@ -1116,7 +1196,68 @@ If there's a string at point, offer that as a default."
"/Stop")
)
(global-set-key (kbd "M-<f7>") (lambda () (interactive) (buildStopIncredibuild)))
;; (global-set-key (kbd "M-<f7>") (lambda () (interactive) (buildStopIncredibuild)))
;;
;; Build system manager - select from multiple different compilation commands
;;
;; Note that names need to be unique (they should be anyways)
(setq macoy-build-system-list (list
'("Stop Incredibuild" buildStopIncredibuild)
)
)
(setq macoy-build-system-default nil)
;; TODO: Figure out why this doesn't work
(defun macoy-build-system-build ()
"Build the build system defined in `macoy-build-system-default'"
(interactive)
(unless macoy-build-system-default
(message "No default build system selected. Run macoy-build-system-select-then-build")
)
(when macoy-build-system-default
(message "Building %s" (car macoy-build-system-default))
(let ((build-function (nth 1 macoy-build-system-default)))
(call-interactively build-function)
)
)
)
(defun macoy-build-system-select ()
"Select default build system using Ido"
(interactive)
;; Use Ido to pick the build system
(let ((build-system-ido-list nil) (selected-build-system nil))
(message "Going to build list")
;; Build a list of only the names of build systems
(dolist (build-system macoy-build-system-list build-system-ido-list)
(add-to-list 'build-system-ido-list (car build-system))
)
(message "build list completed, going to set selected-build-system via Ido")
;; Let the user select the build system using Ido
(setq selected-build-system (ido-completing-read "Build system: " build-system-ido-list))
(message "Build system set; finding by string and setting the default")
(dolist (build-system macoy-build-system-list)
(when (string-equal selected-build-system (car build-system))
(setq macoy-build-system-default build-system)
)
)
)
)
(defun macoy-build-system-select-then-build ()
"Select a build from `macoy-build-system-list' and build it"
(interactive)
(call-interactively 'macoy-build-system-select)
;; Execute the build
(macoy-build-system-build)
)
(global-set-key (kbd "<f7>") 'macoy-build-system-build)
(global-set-key (kbd "S-<f7>") 'macoy-build-system-select-then-build)
;;
;; Custom multiple cursors cut/copy/paste handling
@ -1463,7 +1604,11 @@ If there's a string at point, offer that as a default."
"To be run as a hook for `dired-mode'."
(dired-hide-details-mode 1))
(add-hook 'dired-mode-hook 'macoy-dired-mode-setup)
(define-key dired-mode-map (kbd "<backspace>") 'dired-up-directory)
;; Reuse buffer (from http://ergoemacs.org/emacs/emacs_dired_tips.html)
;; Was dired-advertised-find-file
(define-key dired-mode-map (kbd "<return>") 'dired-find-alternate-file)
;; Was dired-up-directory
(define-key dired-mode-map (kbd "<backspace>") (lambda () (interactive) (find-alternate-file "..")))
;; Compilation mode customizations
(define-key compilation-mode-map (kbd "n") 'compilation-next-error)
@ -1627,8 +1772,10 @@ static char *gnus-pointer[] = {
;; I put it down here so it happens after custom-set-variables sets the theme
;; Set the border color to the fringe to have less contrast-y line (generally; will vary per theme)
(set-face-background 'vertical-border (face-background 'fringe))
(set-face-foreground 'vertical-border (face-background 'vertical-border))
;; Commented versions are for when base16-distinct-fringe-background wasn't nil
;; (set-face-background 'vertical-border (face-background 'fringe))
;; (set-face-foreground 'vertical-border (face-background 'vertical-border))
(set-face-foreground 'vertical-border (face-foreground 'font-lock-comment-delimiter-face))
;; Make the fringe indicators a little more subdued. This might be too much if I start
;; using the fringe for anything more than wrapping indicators, but for now it is fine
@ -1693,3 +1840,4 @@ static char *gnus-pointer[] = {
;;
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'dired-find-alternate-file 'disabled nil)

Loading…
Cancel
Save