Compare commits

..

No commits in common. "7db9f8d56cbc3e49addfbe09867d0fcbc595fb1c" and "8df66edf2594467e110db782a6fc55adfd3f0776" have entirely different histories.

2 changed files with 35 additions and 79 deletions

View File

@ -589,6 +589,7 @@
db/run-or-hide-ansi-term
db/hex-to-ascii
db/text-to-hex
conditionally-enable-lispy
turn-on-lispy-when-available
turn-on-flycheck-when-file
db/sort-nsm-permanent-settings
@ -611,8 +612,7 @@
db/sync-magit-repos-from-projectile
db/replace-variables-in-string
db/dired-ediff-files
db/grep-read-files
db/make-selector-from-table-header))
db/grep-read-files))
(use-package db-hydras
:commands (hydra-toggle/body

View File

@ -250,6 +250,16 @@ FORMAT-STRING defaults to some ISO 8601-like format."
(message time-string)
time-string)))
(defun conditionally-enable-lispy ()
"Enable lispy-mode when in `eval-expression or in
`pp-eval-expression. lispy must have been loaded for this
first, i.e., this function will not automatically load
lispy."
(when (and (featurep 'lispy)
(or (eq this-command 'eval-expression)
(eq this-command 'pp-eval-expression)))
(lispy-mode 1)))
(defun turn-on-lispy-when-available ()
"Activate `lispy in current buffer when possible.
Will print a warning in case of failure."
@ -515,30 +525,30 @@ entries, even if I want to use the input directly."
(stringp bn)
(file-name-nondirectory bn)))
(default-alias
(and fn
(let ((aliases (remove (assoc "all" grep-files-aliases)
grep-files-aliases))
alias)
(while aliases
(setq alias (car aliases)
aliases (cdr aliases))
(if (string-match (mapconcat
#'wildcard-to-regexp
(split-string (cdr alias) nil t)
"\\|")
fn)
(setq aliases nil)
(setq alias nil)))
(cdr alias))))
(and fn
(let ((aliases (remove (assoc "all" grep-files-aliases)
grep-files-aliases))
alias)
(while aliases
(setq alias (car aliases)
aliases (cdr aliases))
(if (string-match (mapconcat
#'wildcard-to-regexp
(split-string (cdr alias) nil t)
"\\|")
fn)
(setq aliases nil)
(setq alias nil)))
(cdr alias))))
(default-extension
(and fn
(let ((ext (file-name-extension fn)))
(and ext (concat "*." ext)))))
(and fn
(let ((ext (file-name-extension fn)))
(and ext (concat "*." ext)))))
(default
(or default-alias
default-extension
(car grep-files-history)
(car (car grep-files-aliases))))
(or default-alias
default-extension
(car grep-files-history)
(car (car grep-files-aliases))))
(files (completing-read
(format "Search for \"%s\" in files matching wildcard: "
regexp)
@ -552,60 +562,6 @@ entries, even if I want to use the input directly."
(or (cdr (assoc files grep-files-aliases))
files))))
(defun db/make-selector-from-table-header (header)
"Return selector function based on names contained in HEADER.
A selector function is a function that receives a KEY (a symbol)
and a ROW (list of values) and returns the value in ROW with the
same index that KEY has in HEADER. A use-case for such a
selector function is to have a table represented as a list of
lists (rows), where the first list (row) is the header and all
subsequent lists (rows) are the actual values; to access values
in all subsequent rows by name, one can use a selector function
on the header to do so.
HEADER must be a list of strings or symbols and must not contain
duplicates when elements are considered as symbols."
(unless (listp header)
(user-error "Header is not a list, cannot create selector"))
(unless (-all? (-orfn #'stringp #'symbolp) header)
(user-error "Header must consist of strings or symbols, cannot create selector"))
(let ((header (-map #'(lambda (elt)
(cond
((symbolp elt) elt)
((stringp elt) (intern (downcase elt)))))
header)))
;; Check for duplicates in HEADER
(when (-reduce-from #'(lambda (val tail)
(or val (memq (cl-first tail)
(cl-rest tail))))
nil
(-tails header))
(user-error "Header contains duplicates, cannot create selector"))
;; Return actual selector
(let* ((lookup-table (make-hash-table)))
(mapc #'(lambda (idx)
(puthash (nth idx header)
idx
lookup-table))
(-iota (length header)))
#'(lambda (column row)
(let ((key (if (symbolp column)
column
(user-error "Unknow key type %s of key %s"
(type-of column)
column))))
(if-let ((idx (gethash key lookup-table)))
(nth idx row)
(user-error "Unknow column name %s" column)))))))
;;; Base45 Decoding
@ -617,7 +573,7 @@ duplicates when elements are considered as symbols."
(-each-indexed (string-to-list base45-alphabet)
(-lambda (index char)
(puthash char index decode-hash-table)
(puthash char index decode-hash-table)
;; Add an encode-hash-table here in case base45-encode-string will ever be
;; written, like so: (puthash index char encode-hash-table)
))