Merge important modes into the global file

master
Jacopo De Simoi 8 years ago
parent 0af513257c
commit edc5b64e93
  1. 216
      global.org
  2. 4
      init/init-elisp.el
  3. 36
      init/init-kde-integration.el
  4. 129
      init/init-org.el

@ -348,37 +348,211 @@
(setq url-proxy-services '(("http" . "127.0.0.1:8118")))
#+END_SRC
* Settings for important major modes
** org-mode
#+BEGIN_SRC emacs-lisp
(require 'org-install)
(require 'org-pomodoro)
(setq org-agenda-files
' ("~/org/notes.org" "~/org/orgzly/work.org" "~/org/orgzly/hack.org" "~/org/orgzly/live.org" "~/org/orgzly/refile.org"))
(add-hook 'org-mode-hook (lambda ()
(turn-on-auto-fill)))
(setq org-default-notes-file "~/org/notes.org")
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)
(add-to-list 'org-structure-template-alist
'("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
(setq org-src-fontify-natively t)
(setq org-capture-templates
'(("t" "TODO today" entry (file+headline "~/org/notes.org" "Tasks")
"* TODO %?\n SCHEDULED: %t" :clock-in t :clock-resume t)
("n" "TODO next" entry (file+headline "~/org/notes.org" "Tasks")
"* NEXT %?\n " :clock-in t :clock-resume t)
("T" "TODO" entry (file+headline "~/org/notes.org" "Tasks")
"* TODO %?\n %a" :clock-in t :clock-resume t)
("i" "Idea" entry (file+headline "~/org/notes.org" "Ideas")
"* IDEA %?\n %u" :clock-in t :clock-resume t )
("j" "Journal" entry (file+datetree "~/org/notes.org")
"* %?\n%U\n" :clock-in t :clock-resume t)
("b" "Break" entry (file+datetree "~/org/notes.org")
"* break %?\n" :clock-in t :clock-resume t)
("e" "Mail To" entry (file+headline "~/org/notes.org" "E-mails")
"* DONE mailto:%?")
("r" "Reply to" entry (file+headline "~/org/notes.org" "E-mails")
"* DONE mailto:%?")))
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)
(setq org-agenda-span 1)
;; Separate drawers for clocking and logs
(setq org-drawers (quote ("PROPERTIES" "CLOCKBOOK")))
;; Save clock data and state changes and notes in the CLOCK drawer
(setq org-clock-into-drawer "CLOCKBOOK")
;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
(setq org-clock-out-remove-zero-time-clocks t)
;; Clock out when moving task to a done state
(setq org-clock-out-when-done t)
(setq org-agenda-custom-commands
'(("h" "Agenda and Android tasks"
((agenda "")
(tags-todo "Android")))
("a" "Main agenda"
((agenda "")
(todo "NEXT|ONGOING")
(tags-todo "hack")
(tags-todo "5m")
(todo "TODO")))
("5" "Agenda and Break tasks"
((agenda "")
(tags-todo "5m")
(tags-todo "20m")))))
;; some super-clever stuff
;; [https://emacs.stackexchange.com/questions/39032/tangle-the-same-src-block-to-different-files]
(defun org-babel-tangle-collect-blocks-handle-tangle-list (&optional language tangle-file)
"Can be used as :override advice for `org-babel-tangle-collect-blocks'.
Handles lists of :tangle files."
(let ((counter 0) last-heading-pos blocks)
(org-babel-map-src-blocks (buffer-file-name)
(let ((current-heading-pos
(org-with-wide-buffer
(org-with-limited-levels (outline-previous-heading)))))
(if (eq last-heading-pos current-heading-pos) (cl-incf counter)
(setq counter 1)
(setq last-heading-pos current-heading-pos)))
(unless (org-in-commented-heading-p)
(let* ((info (org-babel-get-src-block-info 'light))
(src-lang (nth 0 info))
(src-tfiles (cdr (assq :tangle (nth 2 info))))) ; Tobias: accept list for :tangle
(unless (consp src-tfiles) ; Tobias: unify handling of strings and lists for :tangle
(setq src-tfiles (list src-tfiles))) ; Tobias: unify handling
(dolist (src-tfile src-tfiles) ; Tobias: iterate over list
(unless (or (string= src-tfile "no")
(and tangle-file (not (equal tangle-file src-tfile)))
(and language (not (string= language src-lang))))
;; Add the spec for this block to blocks under its
;; language.
(let ((by-lang (assoc src-lang blocks))
(block (org-babel-tangle-single-block counter)))
(setcdr (assoc :tangle (nth 4 block)) src-tfile) ; Tobias:
(if by-lang (setcdr by-lang (cons block (cdr by-lang)))
(push (cons src-lang (list block)) blocks)))))))) ; Tobias: just ()
;; Ensure blocks are in the correct order.
(mapcar (lambda (b) (cons (car b) (nreverse (cdr b)))) blocks)))
(defun org-babel-tangle-single-block-handle-tangle-list (oldfun block-counter &optional only-this-block)
"Can be used as :around advice for `org-babel-tangle-single-block'.
If the :tangle header arg is a list of files. Handle all files"
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(tfiles (cdr (assoc :tangle params))))
(if (null (and only-this-block (consp tfiles)))
(funcall oldfun block-counter only-this-block)
(cl-assert (listp tfiles) nil
":tangle only allows a tangle file name or a list of tangle file names")
(let ((ret (mapcar
(lambda (tfile)
(let (old-get-info)
(cl-letf* (((symbol-function 'old-get-info) (symbol-function 'org-babel-get-src-block-info))
((symbol-function 'org-babel-get-src-block-info)
`(lambda (&rest get-info-args)
(let* ((info (apply 'old-get-info get-info-args))
(params (nth 2 info))
(tfile-cons (assoc :tangle params)))
(setcdr tfile-cons ,tfile)
info))))
(funcall oldfun block-counter only-this-block))))
tfiles)))
(if only-this-block
(list (cons (cl-caaar ret) (mapcar #'cadar ret)))
ret)))))
(advice-add 'org-babel-tangle-collect-blocks :override #'org-babel-tangle-collect-blocks-handle-tangle-list)
(advice-add 'org-babel-tangle-single-block :around #'org-babel-tangle-single-block-handle-tangle-list)
#+END_SRC
** TODO split these up and incorporate them in the main file
#+BEGIN_SRC emacs-lisp
(load "init-latex.el")
(load "init-org.el")
(load "init-c++.el")
(load "init-elisp.el")
(load "init-kde-integration.el")
#+END_SRC
** KDE integration
*** TODO These entries should be added to the subtree once it is split
This function is used to raise the frame associated to the current activity
#+BEGIN_SRC emacs-lisp
(defun select-frame-on-current-activity ()
(select-frame-on-activity (kde-current-activity)))
#+END_SRC
I prefer to keep one server for each KDE activity, so
set the server name to be the name of the current activity
#+BEGIN_SRC emacs-lisp
(setq server-name (kde-current-activity-name))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun kde-current-activity ()
"Returns the current KDE activity"
(substring (shell-command-to-string "qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity") 0 -1)
)
(defun kde-current-activity-name ()
"Returns the name of the current KDE activity"
(substring (shell-command-to-string (concat "qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.ActivityName " (kde-current-activity))) 0 -1))
(defun X-window-id-belongs-to-activity (window-id activity)
(= (shell-command (concat "xprop -id " window-id " | grep _KDE_NET_WM_ACTIVITIES | grep " activity ">/dev/null")) 0)
)
(defun select-frame-on-activity (activity)
(setq framelist (frame-list))
(setq done nil)
(while (and framelist (not done))
(setq cur (car framelist))
(setq cur-id (cdr (assq 'window-id (frame-parameters cur))))
(if cur-id (if (X-window-id-belongs-to-activity cur-id activity) (progn;
(setq done 't) (select-frame cur)) ))
(setq framelist (cdr framelist)))
done
)
(defun select-X-frame ()
(setq framelist (frame-list))
(setq done nil)
(while (and framelist (not done))
(setq cur (car framelist))
(setq cur-id (cdr (assq 'window-id (frame-parameters cur))))
(if cur-id (progn;
(setq done 't) (raise-frame cur)))
(setq framelist (cdr framelist)))
done
)
#+END_SRC
This function is used to raise the frame associated to the current
activity
#+BEGIN_SRC emacs-lisp
(defun select-frame-on-current-activity ()
(select-frame-on-activity (kde-current-activity)))
#+END_SRC
I prefer to keep one server for each KDE activity, so
set the server name to be the name of the current activity
#+BEGIN_SRC emacs-lisp
(setq server-name (kde-current-activity-name))
#+END_SRC
** elisp
*** hooks
#+BEGIN_SRC emacs-lisp
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(outline-minor-mode)
(linum-mode)))
#+END_SRC
*** Replace last sexp
I use this a lot to evaluate (e.g.) quick computations in files
#+BEGIN_SRC emacs-lisp
(defun replace-last-sexp ()
(interactive)
(let ((value (eval (preceding-sexp))))
(kill-sexp -1)
(insert (format "%S" value))))
(global-set-key (kbd "C-c C-x C-e") 'replace-last-sexp)
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun replace-last-sexp ()
(interactive)
(let ((value (eval (preceding-sexp))))
(kill-sexp -1)
(insert (format "%S" value))))
(global-set-key (kbd "C-c C-x C-e") 'replace-last-sexp)
#+END_SRC
** qml
Load ~qml-mode~
#+BEGIN_SRC emacs-lisp

@ -1,4 +0,0 @@
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(outline-minor-mode)
(linum-mode)))

@ -1,36 +0,0 @@
(defun kde-current-activity ()
"Returns the current KDE activity"
(substring (shell-command-to-string "qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity") 0 -1)
)
(defun kde-current-activity-name ()
"Returns the name of the current KDE activity"
(substring (shell-command-to-string (concat "qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.ActivityName " (kde-current-activity))) 0 -1))
(defun X-window-id-belongs-to-activity (window-id activity)
(= (shell-command (concat "xprop -id " window-id " | grep _KDE_NET_WM_ACTIVITIES | grep " activity ">/dev/null")) 0)
)
(defun select-frame-on-activity (activity)
(setq framelist (frame-list))
(setq done nil)
(while (and framelist (not done))
(setq cur (car framelist))
(setq cur-id (cdr (assq 'window-id (frame-parameters cur))))
(if cur-id (if (X-window-id-belongs-to-activity cur-id activity) (progn;
(setq done 't) (select-frame cur)) ))
(setq framelist (cdr framelist)))
done
)
(defun select-X-frame ()
(setq framelist (frame-list))
(setq done nil)
(while (and framelist (not done))
(setq cur (car framelist))
(setq cur-id (cdr (assq 'window-id (frame-parameters cur))))
(if cur-id (progn;
(setq done 't) (raise-frame cur)))
(setq framelist (cdr framelist)))
done
)

@ -1,129 +0,0 @@
;; Init for org-mode
(require 'org-install)
(require 'org-pomodoro)
(setq org-agenda-files
' ("~/org/notes.org" "~/org/orgzly/work.org" "~/org/orgzly/hack.org" "~/org/orgzly/live.org" "~/org/orgzly/refile.org"))
(add-hook 'org-mode-hook (lambda ()
(turn-on-auto-fill)))
(setq org-default-notes-file "~/org/notes.org")
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)
(add-to-list 'org-structure-template-alist
'("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
(setq org-src-fontify-natively t)
(setq org-capture-templates
'(("t" "TODO today" entry (file+headline "~/org/notes.org" "Tasks")
"* TODO %?\n SCHEDULED: %t" :clock-in t :clock-resume t)
("n" "TODO next" entry (file+headline "~/org/notes.org" "Tasks")
"* NEXT %?\n " :clock-in t :clock-resume t)
("T" "TODO" entry (file+headline "~/org/notes.org" "Tasks")
"* TODO %?\n %a" :clock-in t :clock-resume t)
("i" "Idea" entry (file+headline "~/org/notes.org" "Ideas")
"* IDEA %?\n %u" :clock-in t :clock-resume t )
("j" "Journal" entry (file+datetree "~/org/notes.org")
"* %?\n%U\n" :clock-in t :clock-resume t)
("b" "Break" entry (file+datetree "~/org/notes.org")
"* break %?\n" :clock-in t :clock-resume t)
("e" "Mail To" entry (file+headline "~/org/notes.org" "E-mails")
"* DONE mailto:%?")
("r" "Reply to" entry (file+headline "~/org/notes.org" "E-mails")
"* DONE mailto:%?")))
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)
(setq org-agenda-span 1)
;; Separate drawers for clocking and logs
(setq org-drawers (quote ("PROPERTIES" "CLOCKBOOK")))
;; Save clock data and state changes and notes in the CLOCK drawer
(setq org-clock-into-drawer "CLOCKBOOK")
;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
(setq org-clock-out-remove-zero-time-clocks t)
;; Clock out when moving task to a done state
(setq org-clock-out-when-done t)
(setq org-agenda-custom-commands
'(("h" "Agenda and Android tasks"
((agenda "")
(tags-todo "Android")))
("a" "Main agenda"
((agenda "")
(todo "NEXT|ONGOING")
(tags-todo "hack")
(tags-todo "5m")
(todo "TODO")))
("5" "Agenda and Break tasks"
((agenda "")
(tags-todo "5m")
(tags-todo "20m")))))
;; some super-clever stuff
;; [https://emacs.stackexchange.com/questions/39032/tangle-the-same-src-block-to-different-files]
(defun org-babel-tangle-collect-blocks-handle-tangle-list (&optional language tangle-file)
"Can be used as :override advice for `org-babel-tangle-collect-blocks'.
Handles lists of :tangle files."
(let ((counter 0) last-heading-pos blocks)
(org-babel-map-src-blocks (buffer-file-name)
(let ((current-heading-pos
(org-with-wide-buffer
(org-with-limited-levels (outline-previous-heading)))))
(if (eq last-heading-pos current-heading-pos) (cl-incf counter)
(setq counter 1)
(setq last-heading-pos current-heading-pos)))
(unless (org-in-commented-heading-p)
(let* ((info (org-babel-get-src-block-info 'light))
(src-lang (nth 0 info))
(src-tfiles (cdr (assq :tangle (nth 2 info))))) ; Tobias: accept list for :tangle
(unless (consp src-tfiles) ; Tobias: unify handling of strings and lists for :tangle
(setq src-tfiles (list src-tfiles))) ; Tobias: unify handling
(dolist (src-tfile src-tfiles) ; Tobias: iterate over list
(unless (or (string= src-tfile "no")
(and tangle-file (not (equal tangle-file src-tfile)))
(and language (not (string= language src-lang))))
;; Add the spec for this block to blocks under its
;; language.
(let ((by-lang (assoc src-lang blocks))
(block (org-babel-tangle-single-block counter)))
(setcdr (assoc :tangle (nth 4 block)) src-tfile) ; Tobias:
(if by-lang (setcdr by-lang (cons block (cdr by-lang)))
(push (cons src-lang (list block)) blocks)))))))) ; Tobias: just ()
;; Ensure blocks are in the correct order.
(mapcar (lambda (b) (cons (car b) (nreverse (cdr b)))) blocks)))
(defun org-babel-tangle-single-block-handle-tangle-list (oldfun block-counter &optional only-this-block)
"Can be used as :around advice for `org-babel-tangle-single-block'.
If the :tangle header arg is a list of files. Handle all files"
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(tfiles (cdr (assoc :tangle params))))
(if (null (and only-this-block (consp tfiles)))
(funcall oldfun block-counter only-this-block)
(cl-assert (listp tfiles) nil
":tangle only allows a tangle file name or a list of tangle file names")
(let ((ret (mapcar
(lambda (tfile)
(let (old-get-info)
(cl-letf* (((symbol-function 'old-get-info) (symbol-function 'org-babel-get-src-block-info))
((symbol-function 'org-babel-get-src-block-info)
`(lambda (&rest get-info-args)
(let* ((info (apply 'old-get-info get-info-args))
(params (nth 2 info))
(tfile-cons (assoc :tangle params)))
(setcdr tfile-cons ,tfile)
info))))
(funcall oldfun block-counter only-this-block))))
tfiles)))
(if only-this-block
(list (cons (cl-caaar ret) (mapcar #'cadar ret)))
ret)))))
(advice-add 'org-babel-tangle-collect-blocks :override #'org-babel-tangle-collect-blocks-handle-tangle-list)
(advice-add 'org-babel-tangle-single-block :around #'org-babel-tangle-single-block-handle-tangle-list)
Loading…
Cancel
Save