Skip to content

Latest commit

 

History

History
170 lines (150 loc) · 5.92 KB

starter-kit-text.org

File metadata and controls

170 lines (150 loc) · 5.92 KB

Starter Kit Text Editing

This is part of the Emacs Starter Kit.

This file provides settings for text-editing modes and formats, including Mardown and Pandoc, as well as spellchecking and line-wrapping.

Text Management and Appearance

Word-count

Live word count in status bar, via wc. Unfortunately there seems to be a bug – it interacts badly with the smooth scrolling: when you get to the bottom of the buffer it wraps the pointer up to the middle of the screen without moving the text with it, so you end up typing inside the text that’s already there. As a result, it is turned off and has been replaced with a simpler version instead, which gives you a straight count via M-x wc.

;; (autoload 'word-count-mode "word-count"
;; "Minor mode to count words." t nil)
;; (dolist (hook '(org-mode-hook
;; markdown-mode-hook
;; TeX-mode-hook
;; text-mode-hook))
;; (add-hook hook (lambda () (word-count-mode 1))))

(require 'wc)

Line wrapping and position

Sane line wrapping and scrolling for long documents and papers. Plus a function for removing any hard-returns in a document.

(global-visual-line-mode t)
;;; prefer auto-fill to visual line wrap in ESS mode
(add-hook 'ess-mode-hook 'turn-on-auto-fill)
(add-hook 'inferior-ess-mode-hook 'turn-on-auto-fill) 

;;; but turn off auto-fill in tex and markdown
(add-hook 'markdown-mode-hook 'turn-off-auto-fill)
(add-hook 'latex-mode-hook 'turn-off-auto-fill)

;;; unfill paragraph
(defun unfill-paragraph ()
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(global-set-key (kbd "<f6>") 'unfill-paragraph)

;; smooth-scrolling package in src/
(require 'smooth-scrolling)

;; more smooth efforts.
(setq-default 
scroll-conservatively 0
scroll-up-aggressively 0.01
scroll-down-aggressively 0.01)

;; centered-cursor package in src/
;; (and
;;  (require 'centered-cursor-mode)
;;  (global-centered-cursor-mode +1)) 

Spelling

Use cocoAspell instead of ispell. Turned off here because it loads too late. I had to put it in starter-kit-aspell.org.

(setq ispell-program-name "aspell"
     ispell-dictionary "english"
     ispell-dictionary-alist
     (let ((default '("[A-Za-z]" "[^A-Za-z]" "[']" nil
                      ("-B" "-d" "english" "--dict-dir"
                       "/Library/Application Support/cocoAspell/aspell6-en-6.0-0")
                      nil iso-8859-1)))
       `((nil ,@default)
         ("english" ,@default))))

   ;; ispell --- make ispell skip \citep, \citet etc in .tex files.
   (setq ispell-tex-skip-alists
   '((;;("%\\[" . "%\\]") ; AMStex block comment...
   ;; All the standard LaTeX keywords from L. Lamport's guide:
   ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
   ;; \label, \nocite, \rule (in ispell - rest included here)
   ("\\\\addcontentsline"              ispell-tex-arg-end 2)
   ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
   ("\\\\\\([aA]lph\\|arabic\\)"   ispell-tex-arg-end)
   ("\\\\author"                         ispell-tex-arg-end)
   ;; New regexps here --- kjh
   ("\\\\\\(text\\|paren\\)cite" ispell-tex-arg-end)
   ("\\\\cite\\(t\\|p\\|year\\|yearpar\\)" ispell-tex-arg-end)
   ("\\\\bibliographystyle"                ispell-tex-arg-end)
   ("\\\\makebox"                  ispell-tex-arg-end 0)
   ("\\\\e?psfig"                  ispell-tex-arg-end)
   ("\\\\document\\(class\\|style\\)" .
   "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
   (;; delimited with \begin.  In ispell: displaymath, eqnarray, eqnarray*,
   ;; equation, minipage, picture, tabular, tabular* (ispell)
   ("\\(figure\\|table\\)\\*?"     ispell-tex-arg-end 0)
   ("list"                                 ispell-tex-arg-end 2)
   ("program"             . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
   ("verbatim\\*?"        . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))

AutoPair Mode

TextMate-like autopairing of quotes and parentheses. Trying out instead of Skeleton Mode.

(require 'autopair)
(autopair-global-mode) ;; enable autopair in all buffers 
(setq autopair-autowrap t)

Skeleton mode

Turned off by default. Enable skeleton mode in ESS for paired insertion

(require 'skeleton)
(setq skeleton-pair t)
(defvar my-skeleton-pair-alist
'((?\) . ?\()
(?\] . ?\[)
(?} . ?{)
(?" . ?")))

(defun my-skeleton-pair-end (arg)
"Skip the char if it is an ending, otherwise insert it."
(interactive "*p")
(let ((char last-command-char))
(if (and (assq char my-skeleton-pair-alist)
(eq char (following-char)))
(forward-char)
(self-insert-command (prefix-numeric-value arg)))))

(dolist (pair my-skeleton-pair-alist)
(global-set-key (char-to-string (first pair))
'my-skeleton-pair-end)
;; If the char for begin and end is the same,
;; use the original skeleton
(global-set-key (char-to-string (rest pair))
'skeleton-pair-insert-maybe))

Markdown

Markdown mode support.

(autoload 'markdown-mode "markdown-mode.el"
"Major mode for editing Markdown files" t)
(setq auto-mode-alist
(cons '("\\.Markdown" . markdown-mode) auto-mode-alist)
)
(setq auto-mode-alist
(cons '("\\.MarkDown" . markdown-mode) auto-mode-alist)
)
(setq auto-mode-alist
(cons '("\\.markdown" . markdown-mode) auto-mode-alist)
)
(setq auto-mode-alist
(cons '("\\.md" . markdown-mode) auto-mode-alist)
)