index all rss twitter github linkedin email

Álvaro Ramírez

02 March 2016 Emacs lisp snippets

Find file upwards, up parents, up hierarchy

(locate-dominating-file FILE NAME)

Find executable in PATH

(executable-find COMMAND)

Read string with completion (helm/ido/ivy friendly)

(completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD)

Execute command/process and return list (similar to shell-command-to-string)

(process-lines PROGRAM &rest ARGS)

Iterating org buffer

(org-element-map (org-element-parse-buffer) '(headline link)
  (lambda (element)
    (cond
     ((and (eq (org-element-type element) 'headline)
           (= (org-element-property :level element) 1))
      (print "headline"))
     ((eq (org-element-type element) 'link)
      (print "link")))
    nil))