bianle
12/16/2016 - 6:28 AM

emacs

emacs

;;------------------------------------------------------------------
;; copy a line
;;------------------------------------------------------------------
(defun copy-line (arg)
  "Copy lines (as many as prefix argument) in the kill ring"
  (interactive "p")
  (kill-ring-save (line-beginning-position)
                  (line-beginning-position (+ 1 arg)))
  (message "%d line%s copied" arg (if (= 1 arg) "" "s")))

(global-set-key "\C-c\C-k" 'copy-line)


;;------------------------------------------------------------------
;; exec-path-from-shell
;;------------------------------------------------------------------
(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))
  
  
;; Shorter modeline

(defvar mode-line-cleaner-alist
  '(
    (auto-complete-mode . "ⓐ")
    ;;Major modes
    (lisp-interaction-mode . "λ")
    (yas-minor-mode . "ⓨ")
    (undo-tree-mode . "UndoTree")
    (emacs-lisp-mode . "ε")
    (messages-buffer-mode . "㏒")
    (shell-mode . ">_")
    (isearch-mode . " ⊙△⊙ ")
    )
  "Alist for 'clean-mode-line'.
When you add a new element to the alist, keep in mind that you
must pass the correct minor/major mode symbol and a string you
want to use in the modeline *in lieu of* the original.")

(defun clean-mode-line ()
  (interactive)
  (loop for cleaner in mode-line-cleaner-alist
        do (let* ((mode (car cleaner))
                 (mode-str (cdr cleaner))
                 (old-mode-str (cdr (assq mode minor-mode-alist))))
             (when old-mode-str
                 (setcar old-mode-str mode-str))
               ;; major mode
             (when (eq mode major-mode)
               (setq mode-name mode-str)))))
(add-hook 'after-change-major-mode-hook 'clean-mode-line)

;;------------------------------------------------------------------
;; screenshot in org-mode
;;------------------------------------------------------------------

(defun my-screenshot ()
  "Take a screenshot into a unique-named file in the current buffer file directory and insert a link to this file."
  (interactive)
  (setq filename
        (concat (make-temp-name
                 (concat (file-name-directory (buffer-file-name)) "images/" ) ) ".png"))
  (if (file-accessible-directory-p (concat (file-name-directory (buffer-file-name)) "images/"))
      nil
    (make-directory "images"))
  (call-process-shell-command "screencapture" nil nil nil nil "-i" (concat
                                                            "\"" filename "\"" ))
  (insert (concat "[[" filename "]]"))
  (org-display-inline-images)
  )

(global-set-key (kbd "s-p") 'my-screenshot)


;;------------------------------------------------------------------
;; my-dnd-func
;;------------------------------------------------------------------
(defun my-dnd-func (event)
  (interactive "e")
  (goto-char (nth 1 (event-start event)))
  (x-focus-frame nil)
  (let* ((payload (car (last event)))
         (type (car payload))
         (fname (cadr payload))
         (img-regexp "\\(png\\|jp[e]?g\\)\\>"))
    (cond
     ;; insert image link
     ((and  (eq 'drag-n-drop (car event))
            (eq 'file type)
            (string-match img-regexp fname))
      (insert (format "[[%s]]" fname))
      (org-display-inline-images t t))
     ;; insert image link with caption
     ((and  (eq 'C-drag-n-drop (car event))
            (eq 'file type)
            (string-match img-regexp fname))
      (insert "#+ATTR_ORG: :width 300\n")
      (insert (concat  "#+CAPTION: " (read-input "Caption: ") "\n"))
      (insert (format "[[%s]]" fname))
      (org-display-inline-images t t))
     ;; C-drag-n-drop to open a file
     ((and  (eq 'C-drag-n-drop (car event))
            (eq 'file type))
      (find-file fname))
     ((and (eq 'M-drag-n-drop (car event))
           (eq 'file type))
      (insert (format "[[attachfile:%s]]" fname)))
     ;; regular drag and drop on file
     ((eq 'file type)
      (insert (format "[[%s]]\n" fname)))
     (t
      (error "I am not equipped for dnd on %s" payload)))))

(require 'org)
(define-key org-mode-map (kbd "<drag-n-drop>") 'my-dnd-func)
(define-key org-mode-map (kbd "<C-drag-n-drop>") 'my-dnd-func)
(define-key org-mode-map (kbd "<M-drag-n-drop>") 'my-dnd-func)

;;------------------------------------------------------------------
;; livedown
;;------------------------------------------------------------------

(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/livedown.el"))

(require 'livedown)
(global-set-key (kbd "C-M-m") 'livedown:preview)



;;------------------------------------------------------------------
;; mew 
;;------------------------------------------------------------------
(autoload 'mew "mew" nil t)
(autoload 'mew-send "mew" nil t)
(setq mew-use-cached-passwd t)
(setq mew-pop-delete nil)
;; Optional setup (Read Mail menu for Emacs 21):
(if (boundp 'read-mail-command)
(setq read-mail-command 'mew))
;; Optional setup (e.g. C-xm for sending a message):
(autoload 'mew-user-agent-compose "mew" nil t)
(if (boundp 'mail-user-agent)
(setq mail-user-agent 'mew-user-agent))
(if (fboundp 'define-mail-user-agent)
(define-mail-user-agent
'mew-user-agent
'mew-user-agent-compose
'mew-draft-send-message
'mew-draft-kill
'mew-send-hook))
(when (boundp 'utf-translate-cjk)
(setq utf-translate-cjk t)
(custom-set-variables
'(utf-translate-cjk t)))
(if (fboundp 'utf-translate-cjk-mode)
(utf-translate-cjk-mode 1))
;;用w3m来读html格式邮件
(setq mew-mime-multipart-alternative-list '("Text/Html" "Text/Plain" "*."))
(condition-case nil
(require 'mew-w3m)
(file-error nil))
(setq mew-use-text/html t)
;;mail account config
(setq mew-config-alist
'(
("default"
(pop-server "pop.163.com")
(name "163")
(user "i9erle")
(mail-domain "163.com")
(pop-auth pass)
(pop-user "i9erle@163.com")
(smtp-user "i9erle@163.com")
(smtp-server "smtp.163.com")
)
)
)
;;设置邮件签名档
(setq mew-signature-file "~/Mail/signature")
(setq mew-signature-as-lastpart t)
(setq mew-signature-insert-last t)
(add-hook 'mew-before-cite-hook 'mew-header-goto-body)
(add-hook 'mew-draft-mode-newdraft-hook 'mew-draft-insert-signature)
;;设置邮件分类
(setq mew-refile-guess-alist
'(("To:"
("@163.com" . "+Mail/163"))
("Cc:"
("@163.com" . "+Mail/163"))
(nil . "+inbox")))
(setq mew-refile-guess-control
'(mew-refile-guess-by-alist))
;;设置邮件显示栏目
(setq mew-summary-form
'(type (10 date) " " (40 from) " " t (0 subj)))
(setq mew-summary-form-extract-rule '(name))


;;
;;emacs25.1.1 python-mode 执行'C-c C-p'有警告,暂时没找到好的解决方案关闭`python-shell-completion-native-enable`选项,参考:https://github.com/gregsexton/ob-ipython/issues/28
;;Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native’ was t and "python" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally. 

(setq python-shell-completion-native-enable nil)

(setq mac-command-modifier 'meta)
(setq ns-function-modifier 'hyper)
(setq mac-option-modifier 'super)
(setq mac-control-modifier 'control)