Skip to content

Latest commit

 

History

History
179 lines (150 loc) · 6.39 KB

starter-kit-text.org

File metadata and controls

179 lines (150 loc) · 6.39 KB

Starter Kit Text Editing

This is part of the Emacs Starter Kit.

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

Text Management and Appearance

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.

(when (fboundp 'adaptive-wrap-prefix-mode)
  (defun my-activate-adaptive-wrap-prefix-mode ()
    "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
    (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  (add-hook 'visual-line-mode-hook 'my-activate-adaptive-wrap-prefix-mode))
  (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 
  (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 aspell 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")
                      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]*}"))))

Smartparens Mode

Smart autopairing of quotes and parentheses.

(smartparens-global-mode 1)
(require 'smartparens-config)
(show-smartparens-global-mode +1)

Markdown

Markdown mode support.

    (autoload 'markdown-mode "markdown-mode"
    "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)
    )
    (setq auto-mode-alist
    (cons '("README\\.md" . gfm-mode) auto-mode-alist)
    )

 ;; This function will open Marked.app and monitor the current markdown document
 ;; for anything changes.  In other words, it will live reload and convert the
 ;; markdown documment
 (defun markdown-preview-file ()
   "run Marked on the current file and revert the buffer"
   (interactive)
   (shell-command
    (format "open -a /Applications/Marked\\ 2.app %s"
            (shell-quote-argument (buffer-file-name))))
   )  
 (global-set-key "\C-co" 'markdown-preview-file) 

(add-hook 'markdown-mode-hook 'latex-unicode-simplified)
(message "Starter Kit Text loaded.")

CSV mode

View and edit CSV files. See the CSV mode homepage for more details. From the readme:

In CSV mode, the following commands are available:

  • C-c C-s (`csv-sort-fields’) and C-c C-n (`csv-sort-numeric-fields’) respectively sort lexicographically and numerically on a specified field or column.
  • C-c C-r (`csv-reverse-region’) reverses the order. (These commands are based closely on, and use, code in `sort.el’.)
  • C-c C-k (`csv-kill-fields’) and C-c C-y (`csv-yank-fields’) kill and yank fields or columns, although they do not use the normal kill ring. C-c C-k can kill more than one field at once, but multiple killed fields can be yanked only as a fixed group equivalent to a single field.
  • C-c C-a (`csv-align-fields’) aligns fields into columns
  • C-c C-u (`csv-unalign-fields’) undoes such alignment; separators can be hidden within aligned records.
  • C-c C-t (`csv-transpose’) interchanges rows and columns. For details, see the documentation for the individual commands.

#+srcname csv-mode

(add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode))
(autoload 'csv-mode "csv-mode"
  "Major mode for editing comma-separated value files." t)