Advertisement
devurandom

emacs config erlang jslint php flymake codesniffer autocompl

Aug 18th, 2012
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
newLISP 16.82 KB | None | 0 0
  1. (custom-set-variables
  2.  ;; custom-set-variables was added by Custom.
  3.  ;; If you edit it by hand, you could mess it up, so be careful.
  4.  ;; Your init file should contain only one such instance.
  5.  ;; If there is more than one, they won't work right.
  6.  '(php-completion-file "~/.emacs.d/php-completion-file")
  7.  '(php-manual-path "/your/path/to/manuals/php/php-chunked-xhtml")
  8.  '(scalable-fonts-allowed t)
  9.  '(scroll-bar-mode nil)
  10.  '(show-paren-mode t)
  11.  '(size-indication-mode t)
  12.  '(tool-bar-mode nil)
  13.  '(tooltip-mode nil)
  14.  '(tooltip-use-echo-area t)
  15.  '(x-select-enable-clipboard t))
  16.  
  17. ;;;; (defadvice desktop-restore-file-buffer
  18. ;;;;   (around my-desktop-restore-file-buffer-advice)
  19. ;;;;   "Be non-interactive while starting a daemon."
  20. ;;;;   (if (and (daemonp)
  21. ;;;;            (not server-process))
  22. ;;;;       (let ((noninteractive t))
  23. ;;;;         ad-do-it)
  24. ;;;;     ad-do-it))
  25. ;;;; (ad-activate 'desktop-restore-file-buffer)
  26.  
  27. ;;; desktop-override-stale-locks.el begins here
  28. (defun emacs-process-p (pid)
  29.   "If pid is the process ID of an emacs process, return t, else nil.
  30. Also returns nil if pid is nil."
  31.   (when pid
  32.     (let* ((cmdline-file (concat "/proc/" (int-to-string pid) "/cmdline")))
  33.       (when (file-exists-p cmdline-file)
  34.         (with-temp-buffer
  35.           (insert-file-contents-literally cmdline-file)
  36.           (goto-char (point-min))
  37.           (search-forward "emacs" nil t)
  38.           pid)))))
  39.  
  40. (defadvice desktop-owner (after pry-from-cold-dead-hands activate)
  41.   "Don't allow dead emacsen to own the desktop file."
  42.   (when (not (emacs-process-p ad-return-value))
  43.     (setq ad-return-value nil)))
  44. ;;; desktop-override-stale-locks.el ends here
  45.  
  46. ;;;--------------------------------------------------------------------
  47. ;;; setup plugins
  48. ;;;--------------------------------------------------------------------
  49. (add-to-list 'load-path "~/.emacs.d/")
  50. (add-to-list 'load-path "~/.emacs.d/plugins")
  51.  
  52.  
  53. ;;
  54. ;; el-get
  55. ;;
  56.  
  57. ;;-- (add-to-list 'load-path "~/.emacs.d/el-get/el-get")
  58. ;;--
  59. ;;-- (unless (require 'el-get nil t)
  60. ;;--   (url-retrieve
  61. ;;--    "https://raw.github.com/dimitri/el-get/master/el-get-install.el"
  62. ;;--    (lambda (s)
  63. ;;--      (goto-char (point-max))
  64. ;;--      (eval-print-last-sexp))))
  65. ;;--
  66. (add-to-list 'load-path "~/.emacs.d/el-get/el-get")
  67.  
  68. (unless (require 'el-get nil t)
  69.   (with-current-buffer
  70.       (url-retrieve-synchronously
  71.        "https://raw.github.com/dimitri/el-get/master/el-get-install.el")
  72.     (goto-char (point-max))
  73.     (eval-print-last-sexp)))
  74.  
  75. (el-get 'sync)
  76. ;; el-get ends here
  77.  
  78.  
  79. ;;
  80. ;;  fci
  81. ;;
  82. (setq fci-rule-width 1)
  83. ;; (setq fci-rule-color "darkblue")
  84. (setq fci-rule-color "gray5")
  85. (add-hook 'after-change-major-mode-hook 'fci-mode)
  86. (define-globalized-minor-mode global-fci-mode fci-mode (lambda () (fci-mode 1)))
  87. (global-fci-mode 1)
  88. ;;
  89. ;;  fci ends here
  90. ;;
  91.  
  92.  
  93. ;;
  94. ;; session will conflict in daemon mode, so disabled
  95. ;;
  96. ;; (require 'session)
  97. ;; (add-hook 'after-init-hook 'session-initialize)
  98.  
  99. ;; Selecting color theme can be changes using M-x color-theme-<name>
  100. (require 'color-theme)
  101. (color-theme-initialize)
  102. ;; setting color-theme to my favorite ;-)
  103. (color-theme-hober)
  104.  
  105. ;;;
  106. ;;; emacs nav
  107. ;;;
  108. (nav-disable-overeager-window-splitting)
  109. ;; Optional: set up a quick key to toggle nav
  110. (global-set-key [f8] 'nav-toggle)
  111. ;;;
  112. ;;; emacs nav ends here
  113. ;;;
  114.  
  115. ;;; js2-mode
  116. ;; After js2 has parsed a js file, we look for jslint globals decl comment ("/* global Fred, _, Harry */") and
  117. ;; add any symbols to a buffer-local var of acceptable global vars
  118. ;; Note that we also support the "symbol: true" way of specifying names via a hack (remove any ":true"
  119. ;; to make it look like a plain decl, and any ':false' are left behind so they'll effectively be ignored as
  120. ;; you can;t have a symbol called "someName:false"
  121. (add-hook 'js2-post-parse-callbacks
  122.           (lambda ()
  123.             (when (> (buffer-size) 0)
  124.               (let ((btext (replace-regexp-in-string
  125.                             ": *true" " "
  126.                             (replace-regexp-in-string "[\n\t ]+" " " (buffer-substring-no-properties 1 (buffer-size)) t t))))
  127.                 (mapc (apply-partially 'add-to-list 'js2-additional-externs)
  128.                       (split-string
  129.                        (if (string-match "/\\* *global *\\(.*?\\) *\\*/" btext) (match-string-no-properties 1 btext) "")
  130.                        " *, *" t))
  131.                 ))))
  132. ;;
  133. ;;
  134. ;;
  135.  
  136. ;;; flymake setup
  137. ;;;;
  138. ;;;; working config
  139. ;;;; @see http://www.thoughtspark.org/node/59
  140. ;;;;
  141. ;;;;
  142. (when (load "flymake" t)
  143.   (defun flymake-jslint-init ()
  144.     (let* ((temp-file (flymake-init-create-temp-buffer-copy
  145.                        'flymake-create-temp-inplace))
  146.            (local-file (file-relative-name
  147.                         temp-file
  148.                         (file-name-directory buffer-file-name))))
  149.       ;; Change this path to match where you have created the jslint-wrapper
  150.       (list "~/.emacs.d/scripts/jslint-wrapper" (list local-file))))
  151.  
  152.   (setq flymake-err-line-patterns
  153.         (cons '("^[[:space:]]+#[[:digit:]]+ \\(.+\\)I BLAME BOTH FLYMAKE AND JSLINT.+// Line \\([[:digit:]]+\\), Pos \\([[:digit:]]+\\)$"
  154.                 nil 2 3 1)
  155.               flymake-err-line-patterns))
  156.  
  157.   (add-to-list 'flymake-allowed-file-name-masks
  158.                '("\\.js\\'" flymake-jslint-init)))
  159.  
  160. (add-hook 'js2-mode-hook (lambda () (flymake-mode t)))
  161. ;;;;
  162. ;;;;
  163. ;;;;
  164. ;;;;
  165.  
  166. ;;; js2-mode ends here
  167.  
  168.  
  169. ;;;
  170. ;;;
  171. ;;; php setting
  172. ;;;
  173. ;;;
  174. ;;  @see http://pear.php.net/manual/en/standards.indenting.php
  175. (defun pear/php-mode-init()
  176.   "Set some buffer-local variables."
  177.   (setq case-fold-search t)
  178.   (c-set-offset 'arglist-intro '+)
  179.   (c-set-offset 'arglist-close '0)
  180. )
  181. (add-hook 'php-mode-hook 'pear/php-mode-init)
  182.  
  183. ;;
  184. ;; mmm-mode
  185. ;;
  186. (require 'mmm-mode)
  187. (require 'mmm-auto)
  188.  
  189. (setq mmm-global-mode 'maybe)
  190. ;; WARNING: conflicts with nav
  191. ;; (setq mmm-global-mode t)
  192. ;;;; (mmm-add-mode-ext-class 'html-mode "\\.php\\'" 'html-php)
  193. ;;
  194. ;; mmm-mode ends here
  195. ;;
  196.  
  197. ;;
  198. ;; phpcs
  199. ;; @see http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
  200. ;; @see http://www.illusori.co.uk/blog/2011/07/25/perl_php_static_analysis_with_emacs_flymake.html
  201. ;;
  202. (defun my-php-hook-function ()
  203.  (set (make-local-variable 'compile-command) (format "phpcs --report=emacs --standard=PEAR %s" (buffer-file-name))))
  204. (add-hook 'php-mode-hook 'my-php-hook-function)
  205. ;;;; (require 'flyphpcs)
  206.  
  207. ;;
  208. ;; phpcs ends here
  209. ;;
  210.  
  211. ;;;
  212. ;;; php-doc
  213. ;;;
  214. ;;; Installation:
  215.  
  216. ;; 1. Download php_manaul_en.tar.gz to local
  217. ;; 2. extract to certain directory
  218. ;; 3. add this to .emacs
  219. ;;    (require 'php-doc nil t)
  220. ;;    (setq php-doc-directory "/path/to/php_manual/html")
  221. ;;    (add-hook 'php-mode-hook
  222. ;;              (lambda ()
  223. ;;                (local-set-key "\t" 'php-doc-complete-function)
  224. ;;                (local-set-key (kbd "\C-c h") 'php-doc)
  225. ;;                (set (make-local-variable 'eldoc-documentation-function)
  226. ;;                     'php-doc-eldoc-function)
  227. ;;                (eldoc-mode 1)))
  228.  
  229. ;; Put this file into your load-path and the following into your ~/.emacs:
  230. ;;   (require 'php-doc)
  231.  
  232. ;;; Code:
  233. (require 'php-doc nil t)
  234. (setq php-doc-directory "/your/path/to/manuals/php/php-chunked-xhtml")
  235. (add-hook 'php-mode-hook
  236.           (lambda ()
  237.             (local-set-key "\t" 'php-doc-complete-function)
  238.             (local-set-key (kbd "\C-c h") 'php-doc)
  239.             (set (make-local-variable 'eldoc-documentation-function)
  240.                  'php-doc-eldoc-function)
  241.             (eldoc-mode 1)))
  242.  
  243. (require 'php-doc)
  244. ;;;
  245. ;;; php-doc ends here
  246. ;;;
  247.  
  248.  
  249. ;;
  250. (add-hook 'php-mode-hook 'my-php-mode-stuff)
  251.  
  252. (defun my-php-mode-stuff ()
  253.   (local-set-key (kbd "<f1>") 'my-php-function-lookup)
  254.   (local-set-key (kbd "C-<f1>") 'my-php-symbol-lookup))
  255.  
  256.  
  257. (defun my-php-symbol-lookup ()
  258.   (interactive)
  259.   (let ((symbol (symbol-at-point)))
  260.     (if (not symbol)
  261.         (message "No symbol at point.")
  262.  
  263.       (browse-url (concat "http://php.net/manual-lookup.php?pattern="
  264.                           (symbol-name symbol))))))
  265.  
  266.  
  267. (defun my-php-function-lookup ()
  268.   (interactive)
  269.   (let* ((function (symbol-name (or (symbol-at-point)
  270.                                     (error "No function at point."))))
  271.          (buf (url-retrieve-synchronously (concat "http://php.net/manual-lookup.php?pattern=" function))))
  272.     (with-current-buffer buf
  273.       (goto-char (point-min))
  274.         (let (desc)
  275.           (when (re-search-forward "<div class=\"methodsynopsis dc-description\">\\(\\(.\\|\n\\)*?\\)</div>" nil t)
  276.             (setq desc
  277.               (replace-regexp-in-string
  278.                 " +" " "
  279.                 (replace-regexp-in-string
  280.                   "\n" ""
  281.                   (replace-regexp-in-string "<.*?>" "" (match-string-no-properties 1)))))
  282.  
  283.             (when (re-search-forward "<p class=\"para rdfs-comment\">\\(\\(.\\|\n\\)*?\\)</p>" nil t)
  284.               (setq desc
  285.                     (concat desc "\n\n"
  286.                             (replace-regexp-in-string
  287.                              " +" " "
  288.                              (replace-regexp-in-string
  289.                               "\n" ""
  290.                               (replace-regexp-in-string "<.*?>" "" (match-string-no-properties 1))))))))
  291.  
  292.           (if desc
  293.               (message desc)
  294.             (message "Could not extract function info. Press C-F1 to go the description."))))
  295.     (kill-buffer buf)))
  296. ;;
  297.  
  298.  
  299. ;;;
  300. ;;;
  301. ;;; php setting ends here
  302. ;;;
  303. ;;;
  304.  
  305.  
  306. ;;
  307. ;; yasnippet
  308. ;;
  309. (add-to-list 'load-path
  310.               "~/.emacs.d/plugins/yasnippet")
  311. (require 'yasnippet)
  312.  
  313. ;; @see http://capitaomorte.github.com/yasnippet/snippet-organization.html
  314. (setq yas/root-directory
  315.       '(
  316.         "~/.emacs.d/plugins/yasnippet/snippets"
  317.         ;; "~/.emacs.d/snippets/minimal-yasnippet-php-mode"
  318.         ;; "~/.emacs.d/snippets/yas.alt/common/text-mode"
  319.         ;; "~/.emacs.d/snippets/yasnippets-jquery"
  320.         "~/.emacs.d/snippets/php-mode"
  321.         "~/.emacs.d/snippets/js2-mode"
  322.       )
  323. )
  324.  
  325. (yas/global-mode 1)
  326.  
  327. ;; (setq yas/trigger-key (kbd "<C-M-Tab>"))
  328. ;; (add-hook 'yas/minor-mode-on-hook
  329. ;;           '(lambda ()
  330. ;;             (define-key yas/minor-mode-map yas/trigger-key 'yas/expand)))
  331.  
  332. ;;
  333. ;; yasnippet ends here
  334. ;;
  335.  
  336.  
  337. ;;
  338. ;; flymake-phpcs
  339. ;; @see https://github.com/illusori/emacs-flymake-phpcs
  340. ;;
  341.  
  342. ;; If flymake_phpcs isn't found correctly, specify the full path
  343. (setq flymake-phpcs-command "~/.emacs.d/plugins/emacs-flymake-phpcs/bin/flymake_phpcs")
  344.  
  345. ;; Customize the coding standard checked by phpcs
  346. ;; (setq flymake-phpcs-standard
  347. ;;  "~/projects/devtools/php_codesniffer/MyCompanyStandard")
  348. (setq flymake-phpcs-standard
  349.       "~/src/mypear/php/PHP/CodeSniffer/Standards/Varcheck")
  350.  
  351. ;; Show the name of sniffs in warnings (eg show
  352. ;; "Generic.CodeAnalysis.VariableAnalysis.UnusedVariable" in an unused
  353. ;; variable warning)
  354. (setq flymake-phpcs-show-rule t)
  355.  
  356. (add-to-list 'load-path
  357.               "~/.emacs.d/plugins/emacs-flymake-phpcs")
  358. (require 'flymake-phpcs)
  359. ;;
  360. ;; flymake-phpcs ends here
  361. ;;
  362.  
  363.  
  364.  
  365. ;;
  366. ;;  erlang
  367. ;;
  368. (add-to-list 'load-path "~/lib/erlang/distel/elisp")
  369. (require 'distel)
  370. (distel-setup)
  371.  
  372. ;; nitrogen
  373. (require 'nitrogen-mode)
  374. ;;
  375. ;;  erlang ends here
  376. ;;
  377.  
  378.  
  379.  
  380.  
  381.  
  382. ;;; setup plugins ends here
  383.  
  384.  
  385. ;;;--------------------------------------------------------------------
  386. ;;; some variables
  387. ;;;--------------------------------------------------------------------
  388. (setq-default indent-tabs-mode nil)       ; never use tabs - only spaces
  389. (setq-default indicate-empty-lines t)     ; show empty lines in the fringe
  390. (setq c-basic-offset 4)                   ; set indentation to four spaces
  391. (setq column-number-mode t)               ; show column numbers on the modeline
  392. (setq require-final-newline t)            ; automatically put newline at end of file
  393. ;;; some variables ends here
  394.  
  395. ;;;--------------------------------------------------------------------
  396. ;;; my settings
  397. ;;;--------------------------------------------------------------------
  398.  
  399. ;; Load the cua mode, provides windows like key combinations (build into emacs 22.1)
  400. (cua-mode t)
  401.  
  402. ;; @see http://xahlee.org/emacs/emacs_make_modern.html
  403. (delete-selection-mode 1) ; delete seleted text when typing
  404. (global-linum-mode 1) ; display line numbers in margin. Emacs 23 only.
  405.  
  406. ;;; (setq make-backup-files nil) ; stop creating those backup~ files
  407. ;;; (setq auto-save-default nil) ; stop creating those #autosave# files
  408.  
  409.  
  410. ;; hilight current line
  411. (global-hl-line-mode 1)
  412. ;; To customize the background color
  413. (set-face-foreground 'hl-line "gray")
  414. (set-face-background 'hl-line "#101010")
  415.  
  416. ;; save desktop
  417. (desktop-save-mode 1)
  418. (add-hook 'auto-save-hook
  419.           (lambda ()
  420.             (desktop-save-in-desktop-dir)))
  421.  
  422. (ido-mode t)
  423. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  424.  
  425. ;; (iswitchb-mode 1) ??????????????????
  426. (global-set-key "\C-x\C-b" 'ibuffer)
  427.  
  428. ;; Enable
  429. (setq-default fill-column 72)
  430.  
  431. ;;-- ;; whitespace-mode free of trailing whitespace and to use 80-column
  432. ;;-- ;; width, standard indentation
  433. ;;-- (setq whitespace-style '(trailing lines space-before-tab
  434. ;;--                                   indentation space-after-tab)
  435. ;;--       whitespace-line-column 80)
  436.  
  437.  
  438. ;; @see http://web.archive.org/web/20070114052937/http://dima-exe.ru/the-effective-emacs-translation
  439. (global-set-key "\C-c\C-k" 'kill-region)
  440. ;;
  441.  
  442. ;; backup
  443. (setq
  444.    backup-by-copying t      ; don't clobber symlinks
  445.    backup-directory-alist
  446.     '(("." . "~/.saves"))    ; don't litter my fs tree
  447.    delete-old-versions t
  448.    kept-new-versions 6
  449.    kept-old-versions 2
  450.    version-control t)       ; use versioned backups
  451. ;; backup ends here
  452.  
  453. ;; Toggle automatic parens pairing (Electric Pair mode)
  454. (electric-pair-mode t)
  455.  
  456. ;;; my settings ends here
  457.  
  458.  
  459.  
  460. ;;;--------------------------------------------------------------------
  461. ;;; some macro
  462. ;;;--------------------------------------------------------------------
  463.  
  464.  
  465. ;;; ;; duplicate line
  466. ;;; (defun jr-duplicate-line ()
  467. ;;;     "EASY"
  468. ;;;     (interactive)
  469. ;;;     (save-excursion
  470. ;;;       (let ((line-text (buffer-substring-no-properties
  471. ;;;                         (line-beginning-position)
  472. ;;;                         (line-end-position))))
  473. ;;;         (move-end-of-line 1)
  474. ;;;         (newline)
  475. ;;;         (insert line-text))))
  476. ;;;   (global-set-key "\C-cd" 'jr-duplicate-line)
  477. ;;; ;; duplicate line ends here
  478.  
  479. ;;
  480. ;; duplicate-current-line-or-region
  481. ;; @see http://tuxicity.se/emacs/elisp/2010/03/11/duplicate-current-line-or-region-in-emacs.html
  482. ;;
  483. (defun duplicate-current-line-or-region (arg)
  484.   "Duplicates the current line or region ARG times.
  485. If there's no region, the current line will be duplicated. However, if
  486. there's a region, all lines that region covers will be duplicated."
  487.   (interactive "p")
  488.   (let (beg end (origin (point)))
  489.     (if (and mark-active (> (point) (mark)))
  490.         (exchange-point-and-mark))
  491.     (setq beg (line-beginning-position))
  492.     (if mark-active
  493.         (exchange-point-and-mark))
  494.     (setq end (line-end-position))
  495.     (let ((region (buffer-substring-no-properties beg end)))
  496.       (dotimes (i arg)
  497.         (goto-char end)
  498.         (newline)
  499.         (insert region)
  500.         (setq end (point)))
  501.       (goto-char (+ origin (* (length region) arg) arg)))))
  502.  
  503. (global-set-key (kbd "\C-cd") 'duplicate-current-line-or-region)
  504. (global-set-key (kbd "C-c a") 'duplicate-current-line-or-region)
  505. (global-set-key [f5] 'duplicate-current-line-or-region)
  506. (global-set-key (kbd "<C-tab>") 'indent-according-to-mode)
  507. (global-set-key (kbd "<C-M-tab>") 'indent-region)
  508. (global-set-key [f2] 'comment-region)
  509.  
  510. ;;
  511. ;; duplicate-current-line-or-region ends here
  512. ;;
  513.  
  514. ;;
  515. ;; ctags
  516. ;;
  517. (setq path-to-ctags "/usr/bin/ctags") ;; <- your ctags path here
  518.  
  519.   (defun create-tags (dir-name)
  520.     "Create tags file."
  521.     (interactive "DDirectory: ")
  522.     (shell-command
  523.      (format "%s -f %s/TAGS -e -R %s" path-to-ctags dir-name (directory-file-name dir-name)))
  524.   )
  525. ;;
  526. ;; ctags ends here
  527. ;;
  528.  
  529. ;;
  530. (add-to-list 'load-path "~/.emacs.d/")
  531. (require 'auto-complete-config)
  532. (ac-config-default)
  533. ;;
  534.  
  535.  
  536. (defun get-erl-man ()
  537.   (interactive)
  538.   (let* ((man-path "/your/path/to/src/docs/pman/php.net/")
  539.          (man-args (format "-M %s %s" man-path (current-word))))
  540.     (man man-args)))
  541.  
  542. (global-set-key [(f6)] (lambda () (interactive) (get-erl-man)))
  543.  
  544.  
  545. ;;
  546. ;; auto-comlpete
  547. ;;
  548.  
  549. ;; (ac-set-trigger-key "C-TAB")
  550. ;; (setq ac-auto-start nil)
  551. ;; (define-key ac-mode-map (kbd "<C-tab>") 'auto-complete)
  552.  
  553. ;; Show 0.8 second later
  554. (setq ac-auto-show-menu 0.8)
  555.  
  556. ;;
  557. ;; auto-complete ends here
  558. ;;
  559.  
  560. ;;; some macro ends here
  561.  
  562. (server-start)
  563. (custom-set-faces
  564.  ;; custom-set-faces was added by Custom.
  565.  ;; If you edit it by hand, you could mess it up, so be careful.
  566.  ;; Your init file should contain only one such instance.
  567.  ;; If there is more than one, they won't work right.
  568.  )
  569. (put 'upcase-region 'disabled nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement