I have so small problem about in Emacs. I bind helm-do-grep command for Emacs. It's really useful.
I want to search something in current folder.
I searched some codes about that both of them are working but I don't have ability to fix them like what I want.
If you fix them for me I'll be happy thank you.
(defvar my/book-notes-directory "~/Dropbox/books")
(defun my/helm-do-grep-book-notes ()
"Search my book notes."
(interactive)
(helm-do-grep-1 (list my/book-notes-directory)))
(defun my-dir-locals-dir ()
"Return the directory local variables directory.
Code taken from `hack-dir-local-variables'."
(let ((variables-file (dir-locals-find-file (or (buffer-file-name) default-directory)))
(dir-name nil))
(cond,
((stringp variables-file)
(setq dir-name (file-name-directory variables-file)))
((consp variables-file)
(setq dir-name (nth 0 variables-file))))
dir-name))
How about something like this?
(defun my/helm-do-grep-current-directory-tree ()
"Recursively search current directory.
If a parent directory has a `dir-locals-file', use that as the
root instead."
(interactive)
(let ((variables-file (dir-locals-find-file
(or (buffer-file-name) default-directory))))
(helm-do-grep-1
(list
(cond
((stringp variables-file)
(file-name-directory variables-file))
((consp variables-file)
(nth 0 variables-file))
(t default-directory)))
t nil '("*"))))
By the way, if you ask on http://emacs.stackexchange.com , you might get better answers. (And faster, too!) =)
Related
Elisp newbie, looking for help with this.
I have this variable:
(setq bibtex-completion-additional-search-fields '(tags keywords))
I then have a function, which, if this variable is set, then needs to iterate through those field names, and look them up in a data record, concatenate the resulting values into a string, which it returns.
Here's what the data looks like:
("2009-03-01 Zukin, Sharon and Trujillo, Valerie and Frase, Peter and Jackson, Danielle and Recuber, Tim and Walker, Abraham gentrification New Retail Capital and Neighborhood Change: Boutiques and Gentrification in New York City article zukin_new_2009"
("date" . "2009-03-01")
("author" . "Zukin, Sharon and Trujillo, Valerie and Frase, Peter and Jackson, Danielle and Recuber, Tim and Walker, Abraham")
("tags" . "gentrification, retail")
("title" . "New {{Retail Capital}} and {{Neighborhood Change}}: {{Boutiques}} and {{Gentrification}} in {{New York City}}")
("=type=" . "article")
("=key=" . "zukin_new_2009"))
This is what I have for the function ATM, which I know is wrong. But I can't wrap my head around how to do this in elisp (I have more experience with Python and Ruby).
(defun bibtex-completion--get-extra-search-data (candidate)
"Return extended search metadata as string."
(if bibtex-completion-additional-search-fields
; if the data is present, pull its value(s), join into a single string
; TODO FIX ME, this is wrong
(format "%s" (cl-loop
for field in bibtex-completion-additional-search-fields
collect
(cdr (assoc field (cdr candidate)))
))))
So with the example data above, the function should return that string "gentrification, retail". And if that record were to have a keyword field with "foo", the return string would be "gentrification, retail, foo" (or could just be space-separated; not sure it matters).
First, the keys in your data structure are strings, not symbols. So, you could change your lookup fields,
(setq bibtex-completion-additional-search-fields '("tags" "keywords"))
but, using symbols as the cars in the candidate data structure is probably better (efficiency-wise I believe).
The canonical elisp for joining list into string is
(mapconcat #'identity ...),
(mapconcat
#'identity
(delq nil
(cl-loop for field in bibtex-completion-additional-search-fields
collect (cdr (assoc field (cdr candidate)))))
", ")
I tried to write a set of functions that check the expiration date for a domain name:
(ql:quickload 'inferior-shell)
(defun whois-lookup (site)
(let ((request (format nil "whois ~a" site)))
(inferior-shell:run/ss request)))
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(string> input test-string)))
(defun domain-expiration-date (site)
(with-input-from-string (input (whois-lookup site))
(loop for line = (read-line input nil nil)
while line do
(when (match-expiration-string line)
(format t "~A~%~t~A ~%" site line)))))
I'd call it like this: (domain-expiration-date "startpage.com").
Unfortunately, instead of just displaying the relevant line, it shows all of them.
match-expiration-string seems to be working correctly, so I have no idea what the problem is.
CL-USER> (match-expiration-string "Registrar Registration Expiration Date: 2016-05")
39 (6 bits, #x27, #o47, #b100111)
CL-USER> (match-expiration-string "Registrar Registration Expiration ")
NIL
As suggested by jkiiski, it works with a regular expression:
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(ppcre:scan test-string input)))
==>
CL-USER> (domain-expiration-date "startpage.com")
startpage.com
Registrar Registration Expiration Date: 2018-10-10T04:00:00Z
NIL
Like Joshua Taylor says, you don't need regex, only search. I also noticed that "Registrar Registration Expiration Date:" wasn't in every whois response, so I modified the search (and made place in case I needed other search strings for other types of domains):
(defun match-expiration-string (input)
(let ((inclusion-strings '("Expiration Date:"))
(exclusion-strings '("Registrar Registration Expiration Date:")))
(when (some #'(lambda (s) (search s input))
inclusion-strings)
(notany #'(lambda (s) (search s input))
exclusion-strings))))
I just try to read the content of an excel file in clojure. I use the docjure library. When I use the sample code in the REPL, the output is as I wanted it. But after inserting it into the file I got an Wrong number of args - Error for the spreadsheet/select-sheet method.
Here is the code:
(use 'dk.ative.docjure.spreadsheet)
(->> (load-workbook (str (System/getProperty "user.dir") "/resources/public/xls/test.xls")
(select-sheet "menu")
(select-columns {:A :number, :D :name})
))
The args for this method are [name ^Workbook workbook]. Why does it only need one argument in the REPL but two in the file?
Just as Alex said in comments, you messed with parens.
Right now your code code evaluates into:
(load-workbook (str (System/getProperty "user.dir")
"/resources/public/xls/test.xls")
(select-sheet "menu")
(select-columns {:A :number, :D :name}))
Here is how your actual code should look like:
(->> "/resources/public/xls/test.xls"
(str (System/getProperty "user.dir")) ; prefix it with user.dir
load-workbook ; load .xls workbook
(select-sheet "menu") ; select menu sheet
(select-columns {:A :number, :D :name})) ; select some columns
Which evaluates into:
(select-columns {:A :number, :D :name}
(select-sheet "menu"
(load-workbook (str (System/getProperty "user.dir")
"/resources/public/xls/test.xls"))))
As you can see, both select-sheet and select-columns are called with two arguments here.
To better understand how thread-last macro ->> works, see its documentation.
If I do M-x load-file RET /root/.elisp/perl-mode.el RET then this perl-mode.el get loaded correctly.
If I in .emacs add any of these, it doesn't work
(load "/root/.elisp/perl-mode.el")
(load-file "/root/.elisp/perl-mode.el")
I am using emacs 24.1.1.
The error I get is
File mode specification error: (void-function setq-local)
Question
What is the correct way to load perl-mode.el from .emacs?
The macro setq-local was introduced in Emacs 24.3, so this version of perl-mode is too new for the Emacs you're currently running (24.1).
You could upgrade Emacs, or you could just put the definition of setq-local into your .emacs (from here):
(defmacro setq-local (var val)
"Set variable VAR to value VAL in current buffer."
;; Can't use backquote here, it's too early in the bootstrap.
(list 'set (list 'make-local-variable (list 'quote var)) val))
I did lots of search without luck. I think even this is easy but it could help, so here it goes.
Here the goal is to format a kind of Java String to plain text.
For example, consider a String in java code,
logger.LogText( "Hi, this is 1st line " + "\n" +
"speak sth. in 2nd line " + "\n" +
"answered...? ");
and i want to copy from the whole String and paste to my plain text file, then run
M-x some-format-function-by-template-on-selection
and i got a result
Hi, this is 1st line
speak sth. in 2nd line
answered...?
Is there a built-in command for this?
It's not have to use template, but don't you think it's cool?
Currently i try to use 'align' to work around.
The built-in commands are the regexp functions :-)
(defun my-reduce-to-string (start end)
"Extract a quoted string from the selected region."
(interactive "r")
(let* ((text1 (replace-regexp-in-string ".*?\"\\([^\"]+\\)\"[^\"]*" "\\1"
(buffer-substring start end)))
(text (replace-regexp-in-string "\\\\n" "\n" text1)))
(delete-region start end)
(insert text)))
Note that this is a destructive function -- it replaces the text in the buffer as requested.