From 3797f203aff0f28a9d97cbe68d6d43bdbd91b794 Mon Sep 17 00:00:00 2001 From: Iain Bethune Date: Mon, 27 Jan 2014 09:35:03 +0000 Subject: [PATCH] Added folding/unfolding to emacs edit mode (Lianheng Tong) svn-origin-rev: 13499 --- tools/input_editing/emacs/README | 23 ++++++++++++++++------- tools/input_editing/emacs/cp2k-mode.el | 12 +++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/tools/input_editing/emacs/README b/tools/input_editing/emacs/README index ac683481da..115f203f34 100644 --- a/tools/input_editing/emacs/README +++ b/tools/input_editing/emacs/README @@ -4,7 +4,7 @@ #+author: Lianheng Tong #+date: Wednesday, 2014/01/22 -cp2k-mode.el is provides a major mode in emacs for editing CP2K input +cp2k-mode.el provides a major mode in emacs for editing CP2K input files. It has been tested on emacs 2.1, 2.3 and 2.4. * Functionalities @@ -14,6 +14,13 @@ files. It has been tested on emacs 2.1, 2.3 and 2.4. - the keywords - the comment lines - Indents lines according to the CP2K input syntax using key + - Input sections can be folded or unfolded, using emacs outline + minor mode. + - outline-toggle-children when called on a unfolded section, folds + the section recursively; when called on a folded section, + unfolds the top level tree. + - show-all when called unfolds all sections recursively. + - show-subtree when called unfolds a folded section recursively. - New interactive functions: - cp2k-indent-line: indents the line according to CP2K input syntax. @@ -22,12 +29,14 @@ files. It has been tested on emacs 2.1, 2.3 and 2.4. - cp2k-end-of-block: goes to the ending of the subsection, marks the current cursor position. - Key Bindings: - - cp2k-indent-line - - C-j newline-and-indent - - C-c ; comment-region - - C-M-a cp2k-beginning-of-block - - C-M-e cp2k-end-of-block - + - cp2k-indent-line + - C-j newline-and-indent + - C-c ; comment-region + - C-M-a cp2k-beginning-of-block + - C-M-e cp2k-end-of-block + - C-c C-c outline-toggle-children + - C-c C-a show-all + - C-c C-t show-subtree * Installation You need to put cp2k-mode.el in one of your local emacs lisp directories, which is in the search path of your emacs installation. diff --git a/tools/input_editing/emacs/cp2k-mode.el b/tools/input_editing/emacs/cp2k-mode.el index 724792c314..c562726839 100644 --- a/tools/input_editing/emacs/cp2k-mode.el +++ b/tools/input_editing/emacs/cp2k-mode.el @@ -1,6 +1,6 @@ ;;;;; Emacs major mode for cp2k input, written by Lianheng Tong ;;;;; Copyright (c) Lianheng Tong -;;;;; Last modify date: Thursday, 2013/12/05 +;;;;; Last modify date: Saturday, 2014/01/25 ;;;; Syntax highlighting of keywords (defconst cp2k-font-lock-keywords @@ -49,6 +49,9 @@ (define-key map (kbd "TAB") 'cp2k-indent-line) (define-key map (kbd "C-M-a") 'cp2k-beginning-of-block) (define-key map (kbd "C-M-e") 'cp2k-end-of-block) + (define-key map (kbd "C-c C-c") 'outline-toggle-children) + (define-key map (kbd "C-c C-a") 'show-all) + (define-key map (kbd "C-c C-t") 'show-subtree) map) "Keymap for `cp2k-mode'.") @@ -239,5 +242,12 @@ ;;;; Add to autoload alist (add-to-list 'auto-mode-alist '("\\.cp2kin\\'" . cp2k-mode)) +;;;; Setup outline mode +(when (require 'outline nil 'noerror) + (add-hook 'cp2k-mode-hook 'outline-minor-mode) + ;; in outline mode, the level of header depends on the length of + ;; match, which suits our purposes quite well + (setq outline-regexp "[ \t]*\\(&\\|@\\(IF\\|EN\\)\\)")) + ;;;; Last line (provide 'cp2k-mode)