Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (setq initial-scratch-message "")
- (setq visible-bell t)
- (when (window-system)
- (tool-bar-mode 0)
- (when (fboundp 'horizontal-scroll-bar-mode)
- (horizontal-scroll-bar-mode -1))
- (scroll-bar-mode -1))
- (defun unfill-paragraph ()
- "Convert a multi-line paragraph into a single line of text."
- (interactive)
- (let ((fill-column (point-max)))
- (fill-paragraph nil)))
- (global-set-key (kbd "C-x k") 'kill-this-buffer)
- (global-set-key (kbd "C-x K") 'kill-buffer)
- (defadvice helm-find-files (after sudo-find-file activate)
- "Find file as root if necessary."
- (unless (and buffer-file-name
- (file-writable-p buffer-file-name))
- (let* ((file-name (buffer-file-name))
- (file-root (if (string-match "/ssh:\\([^:]+\\):\\(.*\\)" file-name)
- (concat "/ssh:" (match-string 1 file-name)
- "|sudo:" (match-string 1 file-name)
- ":" (match-string 2 file-name))
- (concat "/sudo:localhost:" file-name))))
- (find-alternate-file file-root))))
- (use-package python
- :mode ("\\.py\\'" . python-mode)
- ("\\.wsgi$" . python-mode)
- :interpreter ("python" . python-mode)
- :init
- (setq-default indent-tabs-mode nil)
- :config
- (setq python-indent 4)
- (add-hook 'python-mode-hook 'color-identifiers-mode))
- (use-package org
- :ensure t ; But it comes with Emacs now!?
- :init
- (setq org-use-speed-commands t
- org-return-follows-link t
- org-hide-emphasis-markers t
- org-outline-path-complete-in-steps nil
- org-src-fontify-natively t ;; Pretty code blocks
- org-src-tab-acts-natively t
- org-confirm-babel-evaluate nil
- org-todo-keywords '((sequence "TODO(t)" "DOING(g)" "|" "DONE(d)")
- (sequence "|" "CANCELED(c)")))
- (add-to-list 'auto-mode-alist '("\\.txt\\'" . org-mode))
- (add-to-list 'auto-mode-alist '(".*/[0-9]*$" . org-mode)) ;; Journal entries
- (add-hook 'org-mode-hook 'yas-minor-mode-on)
- :bind (("C-c l" . org-store-link)
- ("C-c c" . org-capture)
- ("C-M-|" . indent-rigidly))
- :config
- (font-lock-add-keywords ; A bit silly but my headers are now
- 'org-mode `(("^\\*+ \\(TODO\\) " ; shorter, and that is nice canceled
- (1 (progn (compose-region (match-beginning 1) (match-end 1) "⚑")
- nil)))
- ("^\\*+ \\(DOING\\) "
- (1 (progn (compose-region (match-beginning 1) (match-end 1) "⚐")
- nil)))
- ("^\\*+ \\(CANCELED\\) "
- (1 (progn (compose-region (match-beginning 1) (match-end 1) "✘")
- nil)))
- ("^\\*+ \\(DONE\\) "
- (1 (progn (compose-region (match-beginning 1) (match-end 1) "✔")
- nil)))))
- (use-package org-journal
- :ensure t
- :init
- (setq org-journal-dir "~/journal/")
- (setq org-journal-date-format "#+TITLE: Journal Entry- %e %b %Y (%A)")
- (setq org-journal-time-format ""))
- (defun get-journal-file-today ()
- "Return filename for today's journal entry."
- (let ((daily-name (format-time-string "%Y%m%d")))
- (expand-file-name (concat org-journal-dir daily-name))))
- (defun journal-file-today ()
- "Create and load a journal file based on today's date."
- (interactive)
- (find-file (get-journal-file-today)))
- (global-set-key (kbd "C-c f j") 'journal-file-today)
- (defun get-journal-file-yesterday ()
- "Return filename for yesterday's journal entry."
- (let* ((yesterday (time-subtract (current-time) (days-to-time 1)))
- (daily-name (format-time-string "%Y%m%d" yesterday)))
- (expand-file-name (concat org-journal-dir daily-name))))
- (defun journal-file-yesterday ()
- "Creates and load a file based on yesterday's date."
- (interactive)
- (find-file (get-journal-file-yesterday)))
- (global-set-key (kbd "C-c f y") 'journal-file-yesterday)
- (defun journal-file-insert ()
- "Insert's the journal heading based on the file's name."
- (interactive)
- (let* ((year (string-to-number (substring (buffer-name) 0 4)))
- (month (string-to-number (substring (buffer-name) 4 6)))
- (day (string-to-number (substring (buffer-name) 6 8)))
- (datim (encode-time 0 0 0 day month year)))
- (insert (format-time-string org-journal-date-format datim))
- (insert "\n\n $0\n") ; Start with a blank separating line
- ;; Note: The `insert-file-contents' leaves the cursor at the
- ;; beginning, so the easiest approach is to insert these files
- ;; in reverse order:
- ;; If the journal entry I'm creating matches today's date:
- (when (equal (file-name-base (buffer-file-name))
- (format-time-string "%Y%m%d"))
- (insert-file-contents "journal-dailies-end.org")
- ;; Insert dailies that only happen once a week:
- (let ((weekday-template (downcase
- (format-time-string "journal-%a.org"))))
- (when (file-exists-p weekday-template)
- (insert-file-contents weekday-template)))
- (insert-file-contents "journal-dailies.org")
- (insert "$0")
- (let ((contents (buffer-string)))
- (delete-region (point-min) (point-max))
- (yas-expand-snippet contents (point-min) (point-max)))))))
- (define-auto-insert "/[0-9]\\{8\\}$" [journal-file-insert])
- (defun journal-last-year-file ()
- "Returns the string corresponding to the journal entry that
- happened 'last year' at this same time (meaning on the same day
- of the week)."
- (let* ((last-year-seconds (- (float-time) (* 365 24 60 60)))
- (last-year (seconds-to-time last-year-seconds))
- (last-year-dow (nth 6 (decode-time last-year)))
- (this-year-dow (nth 6 (decode-time)))
- (difference (if (> this-year-dow last-year-dow)
- (- this-year-dow last-year-dow)
- (- last-year-dow this-year-dow)))
- (target-date-seconds (+ last-year-seconds (* difference 24 60 60)))
- (target-date (seconds-to-time target-date-seconds)))
- (format-time-string "%Y%m%d" target-date)))
- (defun journal-last-year ()
- "Loads last year's journal entry, which is not necessary the
- same day of the month, but will be the same day of the week."
- (interactive)
- (let ((journal-file (concat org-journal-dir (journal-last-year-file))))
- (find-file journal-file)))
- (global-set-key (kbd "C-c f L") 'journal-last-year)
- (setq delete-old-versions -1)
- (setq version-control t)
- (setq vc-make-backup-files t)
- (setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
- (setq savehist-file "~/.emacs.d/savehist")
- (savehist-mode 1)
- (setq history-length t)
- (setq history-delete-duplicates t)
- (setq savehist-save-minibuffer-history 1)
- (setq savehist-additional-variables
- '(kill-ring
- search-ring
- regexp-search-ring))
- (setq sentence-end-double-space nil)
- (use-package helm
- :diminish helm-mode
- :init
- (progn
- (require 'helm-config)
- (setq helm-candidate-number-limit 100)
- ;; From https://gist.github.com/antifuchs/9238468
- (setq helm-idle-delay 0.0 ; update fast sources immediately (doesn't).
- helm-input-idle-delay 0.01 ; this actually updates things
- ; reeeelatively quickly.
- helm-yas-display-key-on-candidate t
- helm-quick-update t
- helm-M-x-requires-pattern nil
- helm-ff-skip-boring-files t)
- (helm-mode))
- :bind (("C-c h" . helm-mini)
- ("C-h a" . helm-apropos)
- ("C-x C-b" . helm-buffers-list)
- ("C-x b" . helm-buffers-list)
- ("M-y" . helm-show-kill-ring)
- ("M-x" . helm-M-x)
- ("C-x c o" . helm-occur)
- ("C-x c s" . helm-swoop)
- ("C-x c y" . helm-yas-complete)
- ("C-x c Y" . helm-yas-create-snippet-on-region)
- ("C-x c b" . my/helm-do-grep-book-notes)
- ("C-x c SPC" . helm-all-mark-rings)))
- (ido-mode -1)
- (ert-deftest my/org-capture-prefill-template ()
- (should
- ;; It should fill things in one field at ia time
- (string=
- (my/org-capture-prefill-template
- "* TODO %^{Task}\nSCHEDULED: %^t\n:PROPERTIES:\n:Effort: %^{effort|1:00|0:05|0:15|0:30|2:00|4:00}\n:END:\n%?\n"
- "Hello World")
- "* TODO Hello World\nSCHEDULED: %^t\n:PROPERTIES:\n:Effort: %^{effort|1:00|0:05|0:15|0:30|2:00|4:00}\n:END:\n%?\n"
- ))
- (should
- (string=
- (my/org-capture-prefill-template
- "* TODO %^{Task}\nSCHEDULED: %^t\n:PROPERTIES:\n:Effort: %^{effort|1:00|0:05|0:15|0:30|2:00|4:00}\n:END:\n%?\n"
- "Hello World" "<2015-01-01>")
- "* TODO Hello World\nSCHEDULED: <2015-01-01>\n:PROPERTIES:\n:Effort: %^{effort|1:00|0:05|0:15|0:30|2:00|4:00}\n:END:\n%?\n"))
- (should
- (string=
- (my/org-capture-prefill-template
- "* TODO %^{Task}\nSCHEDULED: %^t\n:PROPERTIES:\n:Effort: %^{effort|1:00|0:05|0:15|0:30|2:00|4:00}\n:END:\n%?\n"
- "Hello World" "<2015-01-01>" "0:05")
- "* TODO Hello World\nSCHEDULED: <2015-01-01>\n:PROPERTIES:\n:Effort: 0:05\n:END:\n%?\n")))
- (defun my/org-capture-prefill-template (template &rest values)
- "Pre-fill TEMPLATE with VALUES."
- (setq template (or template (org-capture-get :template)))
- (with-temp-buffer
- (insert template)
- (goto-char (point-min))
- (while (re-search-forward
- (concat "%\\("
- "\\[\\(.+\\)\\]\\|"
- "<\\([^>\n]+\\)>\\|"
- "\\([tTuUaliAcxkKInfF]\\)\\|"
- "\\(:[-a-zA-Z]+\\)\\|"
- "\\^\\({\\([^}]*\\)}\\)"
- "?\\([gGtTuUCLp]\\)?\\|"
- "%\\\\\\([1-9][0-9]*\\)"
- "\\)") nil t)
- (if (car values)
- (replace-match (car values) nil t))
- (setq values (cdr values)))
- (buffer-string)))
- (defun my/org-get-current-refile-location ()
- "Return the current entry as a location understood by org-refile."
- (interactive)
- (list (elt (org-heading-components) 4)
- (or buffer-file-name
- (with-current-buffer (buffer-base-buffer (current-buffer))
- buffer-file-name))
- nil
- (point)))
- (defun my/helm-org-create-task (candidate)
- "Creates the task and returns the location."
- (let ((entry (org-capture-select-template "T")))
- (org-capture-set-plist entry)
- (org-capture-get-template)
- (org-capture-set-target-location)
- (condition-case error
- (progn
- (org-capture-put
- :template
- (org-capture-fill-template
- (my/org-capture-prefill-template (org-capture-get :template)
- candidate)))
- (org-capture-place-template
- (equal (car (org-capture-get :target)) 'function))
- (setq org-refile-target-table (org-refile-get-targets))
- ;; Return the new location
- (my/org-get-current-refile-location))
- ((error quit)
- (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
- (error "Capture abort: %s" error)))))
- (defvar my/helm-org-refile-locations nil)
- (defvar my/org-refile-last-location nil)
- (defun my/helm-org-clock-in-and-track-from-refile (candidate)
- (let ((location (org-refile--get-location candidate my/helm-org-refile-locations)))
- (save-window-excursion
- (org-refile 4 nil location)
- (my/org-clock-in-and-track)
- t)))
- (defun my/org-get-todays-items-as-refile-candidates ()
- "Return items scheduled for today, ready for choosing during refiling."
- (delq
- nil
- (mapcar
- (lambda (s)
- (if (get-text-property 0 'org-marker s)
- (list
- s
- (buffer-file-name (marker-buffer (get-text-property 0 'org-marker s)))
- nil
- (marker-position (get-text-property 0 'org-marker s)))))
- (save-window-excursion (my/org-get-entries-fn (calendar-current-date) (calendar-current-date))))))
- ;; Based on http://emacs.stackexchange.com/questions/4063/how-to-get-the-raw-data-for-an-org-mode-agenda-without-an-agenda-view
- (defun my/org-get-entries-fn (begin end)
- "Return org schedule items between BEGIN and END.
- USAGE: (org-get-entries-fn '(6 1 2015) '(6 30 2015))"
- (require 'calendar)
- (require 'org)
- (require 'org-agenda)
- (require 'cl)
- (unless
- (and
- (calendar-date-is-valid-p begin)
- (calendar-date-is-valid-p end))
- (let ((debug-on-quit nil))
- (signal 'quit `("One or both of your gregorian dates are invalid."))))
- (let* (
- result
- (org-agenda-prefix-format " • ")
- (org-agenda-entry-types '(:scheduled))
- (date-after
- (lambda (date num)
- "Return the date after NUM days from DATE."
- (calendar-gregorian-from-absolute
- (+ (calendar-absolute-from-gregorian date) num))))
- (enumerate-days
- (lambda (begin end)
- "Enumerate date objects between BEGIN and END."
- (when (> (calendar-absolute-from-gregorian begin)
- (calendar-absolute-from-gregorian end))
- (error "Invalid period : %S - %S" begin end))
- (let ((d begin) ret (cont t))
- (while cont
- (push (copy-sequence d) ret)
- (setq cont (not (equal d end)))
- (setq d (funcall date-after d 1)))
- (nreverse ret)))) )
- (org-agenda-reset-markers)
- (setq org-agenda-buffer
- (when (buffer-live-p org-agenda-buffer)
- org-agenda-buffer))
- (org-compile-prefix-format nil)
- (setq result
- (loop for date in (funcall enumerate-days begin end) append
- (loop for file in (org-agenda-files nil 'ifmode)
- append
- (progn
- (org-check-agenda-file file)
- (apply 'org-agenda-get-day-entries file date org-agenda-entry-types)))))
- (unless (buffer-live-p (get-buffer org-agenda-buffer-name))
- (get-buffer-create org-agenda-buffer-name))
- (with-current-buffer (get-buffer org-agenda-buffer-name)
- (org-agenda-mode)
- (setq buffer-read-only t)
- (let ((inhibit-read-only t))
- (erase-buffer))
- (mapcar
- (lambda (x)
- (let ((inhibit-read-only t))
- (insert (format "%s" x) "\n")))
- result))
- ;; (display-buffer org-agenda-buffer-name t)
- result))
- (defun my/helm-org-refile-read-location (tbl)
- (setq my/helm-org-refile-locations tbl)
- (helm
- (list
- ;; (helm-build-sync-source "Today's tasks"
- ;; :candidates (mapcar (lambda (a) (cons (car a) a))
- ;; (my/org-get-todays-items-as-refile-candidates))
- ;; :action '(("Select" . identity)
- ;; ("Clock in and track" . my/helm-org-clock-in-and-track-from-refile)
- ;; ("Draw index card" . my/helm-org-prepare-index-card-for-subtree))
- ;; :history 'org-refile-history)
- (helm-build-sync-source "Refile targets"
- :candidates (mapcar (lambda (a) (cons (car a) a)) tbl)
- :action '(("Select" . identity)
- ("Clock in and track" . my/helm-org-clock-in-and-track-from-refile)
- ("Draw index card" . my/helm-org-prepare-index-card-for-subtree))
- :history 'org-refile-history)
- (helm-build-dummy-source "Create task"
- :action (helm-make-actions
- "Create task"
- 'my/helm-org-create-task)))))
- (defun my/org-refile-get-location (&optional prompt default-buffer new-nodes no-exclude)
- "Prompt the user for a refile location, using PROMPT.
- PROMPT should not be suffixed with a colon and a space, because
- this function appends the default value from
- `org-refile-history' automatically, if that is not empty.
- When NO-EXCLUDE is set, do not exclude headlines in the current subtree,
- this is used for the GOTO interface."
- (let ((org-refile-targets org-refile-targets)
- (org-refile-use-outline-path org-refile-use-outline-path)
- excluded-entries)
- (when (and (derived-mode-p 'org-mode)
- (not org-refile-use-cache)
- (not no-exclude))
- (org-map-tree
- (lambda()
- (setq excluded-entries
- (append excluded-entries (list (org-get-heading t t)))))))
- (setq org-refile-target-table
- (org-refile-get-targets default-buffer excluded-entries)))
- (unless org-refile-target-table
- (user-error "No refile targets"))
- (let* ((cbuf (current-buffer))
- (partial-completion-mode nil)
- (cfn (buffer-file-name (buffer-base-buffer cbuf)))
- (cfunc (if (and org-refile-use-outline-path
- org-outline-path-complete-in-steps)
- 'org-olpath-completing-read
- 'org-icompleting-read))
- (extra (if org-refile-use-outline-path "/" ""))
- (cbnex (concat (buffer-name) extra))
- (filename (and cfn (expand-file-name cfn)))
- (tbl (mapcar
- (lambda (x)
- (if (and (not (member org-refile-use-outline-path
- '(file full-file-path)))
- (not (equal filename (nth 1 x))))
- (cons (concat (car x) extra " ("
- (file-name-nondirectory (nth 1 x)) ")")
- (cdr x))
- (cons (concat (car x) extra) (cdr x))))
- org-refile-target-table))
- (completion-ignore-case t)
- cdef
- (prompt (concat prompt
- (or (and (car org-refile-history)
- (concat " (default " (car org-refile-history) ")"))
- (and (assoc cbnex tbl) (setq cdef cbnex)
- (concat " (default " cbnex ")"))) ": "))
- pa answ parent-target child parent old-hist)
- (setq old-hist org-refile-history)
- ;; Use Helm's sources instead
- (setq answ (my/helm-org-refile-read-location tbl))
- (cond
- ((and (stringp answ)
- (setq pa (org-refile--get-location answ tbl)))
- (org-refile-check-position pa)
- (when (or (not org-refile-history)
- (not (eq old-hist org-refile-history))
- (not (equal (car pa) (car org-refile-history))))
- (setq org-refile-history
- (cons (car pa) (if (assoc (car org-refile-history) tbl)
- org-refile-history
- (cdr org-refile-history))))
- (if (equal (car org-refile-history) (nth 1 org-refile-history))
- (pop org-refile-history)))
- (setq my/org-refile-last-location pa)
- pa)
- ((and (stringp answ) (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ))
- (setq parent (match-string 1 answ)
- child (match-string 2 answ))
- (setq parent-target (org-refile--get-location parent tbl))
- (when (and parent-target
- (or (eq new-nodes t)
- (and (eq new-nodes 'confirm)
- (y-or-n-p (format "Create new node \"%s\"? "
- child)))))
- (org-refile-new-child parent-target child)))
- ((listp answ) answ) ;; Sacha: Helm returned a refile location
- ((not (equal answ t))
- (user-error "Invalid target location")))))
- (fset 'org-refile-get-location 'my/org-refile-get-location)
- (prefer-coding-system 'utf-8)
- (when (display-graphic-p)
- (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))
- (use-package helm-swoop
- :bind
- (("C-S-s" . helm-swoop)
- ("M-i" . helm-swoop)
- ("M-s s" . helm-swoop)
- ("M-s M-s" . helm-swoop)
- ("M-I" . helm-swoop-back-to-last-point)
- ("C-c M-i" . helm-multi-swoop)
- ("C-x M-i" . helm-multi-swoop-all)
- )
- :config
- (progn
- (define-key isearch-mode-map (kbd "M-i") 'helm-swoop-from-isearch)
- (define-key helm-swoop-map (kbd "M-i") 'helm-multi-swoop-all-from-helm-swoop))
- )
- (defun my/smarter-move-beginning-of-line (arg)
- "Move point back to indentation of beginning of line.
- Move point to the first non-whitespace character on this line.
- If point is already there, move to the beginning of the line.
- Effectively toggle between the first non-whitespace character and
- the beginning of the line.
- If ARG is not nil or 1, move forward ARG - 1 lines first. If
- point reaches the beginning or end of the buffer, stop there."
- (interactive "^p")
- (setq arg (or arg 1))
- ;; Move lines first
- (when (/= arg 1)
- (let ((line-move-visual nil))
- (forward-line (1- arg))))
- (let ((orig-point (point)))
- (back-to-indentation)
- (when (= orig-point (point))
- (move-beginning-of-line 1))))
- ;; remap C-a to `smarter-move-beginning-of-line'
- (global-set-key [remap move-beginning-of-line]
- 'my/smarter-move-beginning-of-line)
- (use-package yasnippet
- :diminish yas-minor-mode
- :init (yas-global-mode)
- :config
- (progn
- (yas-global-mode)
- (add-hook 'hippie-expand-try-functions-list 'yas-hippie-try-expand)
- (setq yas-key-syntaxes '("w_" "w_." "^ "))
- (setq yas-installed-snippets-dir "~/elisp/yasnippet-snippets")
- (setq yas-expand-only-for-last-commands nil)
- (yas-global-mode 1)
- (bind-key "\t" 'hippie-expand yas-minor-mode-map)
- (add-to-list 'yas-prompt-functions 'shk-yas/helm-prompt)))
- ;; (global-set-key (kbd "C-c y") (lambda () (interactive)
- ;; (yas/load-directory "~/elisp/snippets")))
Advertisement
Add Comment
Please, Sign In to add comment