Showing posts with label Emacs. Show all posts
Showing posts with label Emacs. Show all posts

Sunday, October 26, 2014

How to compile in the current frame in Emacs

;; compilation
(setq compilation-scroll-output t)
(add-to-list 'same-window-buffer-names "*compilation*")
(defun bury-compile-buffer-if-successful (buffer string)
  "Bury a compilation buffer if succeeded without warnings"
  (if (and
         (string-match "compilation" (buffer-name buffer))
         (string-match "finished" string)
         (not (with-current-buffer buffer
                (goto-char (point-min))
                (search-forward "warning" nil t))))
      (with-current-buffer buffer
        (goto-char (point-max))
        (run-with-timer 5 nil
          (lambda (buf)
            (bury-buffer buf)
            (switch-to-prev-buffer (get-buffer-window buf) 'kill))
             buffer))))
(add-hook 'compilation-finish-functions 'bury-compile-buffer-if-successful)


This setting will ask Emacs to compile in the current frame. If there is no error, the compilation buffer will close after 5 seconds; otherwise, it will stop at the first error.

How to enable spell check (Aspell) in Emacs

;; use Aspell
(require 'go-mode-load)
(add-hook 'go-mode-hook
  (lambda ()
    (setq-default)
    (setq tab-width 2)
    (setq standard-indent 2)
    (setq indent-tabs-mode nil)))

How to set line wrap and fill prefix in Emacs

;;line wrap                                                    
(setq-default fill-column 80)
(global-visual-line-mode 1)     ; 1 for on, 0 for off.

(setq-default fill-prefix " ")

This is especially useful when you write latex document.

Friday, October 24, 2014

Emacs Sr-speedbar

;; speedbar
(require 'sr-speedbar)
(setq sr-speedbar-width 20)           ; width
(setq sr-speedbar-max-width 20)
(setq sr-speedbar-right-side nil)     ; put it to the left
(setq speedbar-show-unknown-files t)  ; show all files
(sr-speedbar-open)
(with-current-buffer sr-speedbar-buffer-name
  (setq window-size-fixed 'width))  ; keep width after resize window

Wednesday, October 8, 2014

Compilation under Emacs

;; prevent compiler opens a new frame (put output in current buffer)
(add-to-list 'same-window-buffer-names "*compilation*”)


;; auto scroll compilation output
(setq compilation-scroll-output t)


;; auto close if succeeded
(defun bury-compile-buffer-if-successful (buffer string)
  "Bury a compilation buffer if succeeded without warnings"
  (if (and
         (string-match "compilation" (buffer-name buffer))
         (string-match "finished" string)
         (not (with-current-buffer buffer
                (goto-char (point-min))
                (search-forward "warning" nil t))))
      (with-current-buffer buffer
        (goto-char (point-max))
        (run-with-timer 5 nil
          (lambda (buf)
            (bury-buffer buf)
            (switch-to-prev-buffer (get-buffer-window buf) 'kill))
             buffer))))
(add-hook 'compilation-finish-functions

          'bury-compile-buffer-if-successful)

GDB layout under Emacs

;; invoke
(global-set-key [f8] 'gdb)

;; GDB layout
(defadvice gdb-setup-windows (after activate)
  (gdb-setup-my-windows)
)

(defun gdb-setup-my-windows ()
  (set-window-dedicated-p (selected-window) nil)
  (switch-to-buffer gud-comint-buffer)
  (delete-other-windows)
  (let
    ((win0 (selected-window))             ; source
     (win1 (split-window-horizontally

             (floor (* 0.55 (window-width)))))   ; gdb
     (win2 (split-window-vertically

             (floor (* 0.7 (window-body-height))))) ; bp
    )
    ;; set source buffer
    (set-window-buffer
     win0
     (if gud-last-last-frame
         (gud-find-file (car gud-last-last-frame))
       (if gdb-main-file
           (gud-find-file gdb-main-file)
         (list-buffers-noselect))))
    (setq gdb-source-window win0)

    (select-window win1)
    (split-window-vertically (floor (* 0.7 (window-body-height))))
    (split-window-vertically (floor (* 0.4 (window-body-height))))

    ;; set locals window
    (gdb-set-window-buffer (gdb-get-buffer-create 'gdb-locals-buffer))
    ;; set assembly window
    (other-window 1)
    (gdb-set-window-buffer (gdb-get-buffer-create 'gdb-assembler-buffer))
    ;; set breakpoint buffer
    (other-window 1)
    (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
    ;; set focus on gdb buffer
    (select-window win2)
  )
)

speedbar

1. Download "sr-speedbar.el" into "~.emacs.d/lisp/"

2. Put the following into "~/.emacs"
;; speedbar
(require 'sr-speedbar)
(set 'speedbar-update-flag t)

Set up 80 column indicator in Emacs

 1. Downalod "fill-column-indicator.el" into "~/.emacs.d/listp/"

 2. Put the following commands in .emacs
(require 'fill-column-indicator)
(setq-default fci-rule-column 80)
(setq fci-rule-width 1)
(setq fci-rule-color "grey80")
(setq-default fci-rule-character-color "green")
(add-hook 'after-change-major-mode-hook 'fci-mode)



Emacs configuration

;; start in read-only mode
(add-hook 'find-file-hook (lambda () (setq buffer-read-only t)))

;; disable splash screen and startup message
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)


;; set up layout
(if window-system
    (setq default-frame-alist
      '((height . 42)
        (width . 90)
        (cursor-type . box)
        (foreground-color . "black")
        (background-color . "#FAF9DE")
        (font . "Consolas-13")
        )))

;; disable cursor blink
(blink-cursor-mode 0)

;; set autoload path
(add-to-list 'load-path "~/.emacs.d/lisp/")


;; use y/n to replace yes/no
(fset 'yes-or-no-p 'y-or-n-p)


;; show line number
(setq column-number-mode t)
(global-linum-mode t)
(setq linum-format "%d ")