Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Yaml Editing

Tags:

emacs

yaml

is there any Emacs lisp add-on that allows me to edit or enter data in yaml file easily.

For example:

--- sample yaml file ---
Name : 
Addr :
City :
State:
Zip  :

Phone:
Email
--- End ----

When the file is opened in Emacs, the cursor will be automatically placed at the first Yaml key. In this case "Name:", when I finish entering a name after the "Name:" and hit return, it will automatically move to the next key. in this case "Addr:"

forward / backward tab can be used to move back and forth between keys.

Is there anything out there for this?

Thanks!

like image 451
TX T Avatar asked Sep 28 '12 22:09

TX T


3 Answers

http://emacswiki.org/emacs/YamlMode

like image 55
Andreas Röhler Avatar answered Nov 03 '22 02:11

Andreas Röhler


I gather bits and pieces from the net and got this:

(defun yaml-next-field ()
  "Jump to next yaml field"
  (interactive)
  (search-forward-regexp ": *"))
(defun yaml-prev-field ()
  "Jump to next yaml field"
  (interactive)
  (search-backward-regexp ": *"))
(add-hook 'yaml-mode-hook
          '(lambda ()
             (define-key yaml-mode-map "\C-m" 'newline-and-indent)
             (define-key yaml-mode-map "\M-\r" 'insert-ts)
             (define-key yaml-mode-map (kbd "C-<tab>") 'yaml-next-field)
             (define-key yaml-mode-map (kbd "C-S-<tab>") 'yaml-prev-field)
             ))
like image 3
TX T Avatar answered Nov 03 '22 00:11

TX T


You can define a custom macro that does what you want.

It could something like this:

;; define named macro
(fset 'jump-next-colon
  [?\C-f ?\C-s ?: ?\C-  ? ])
;; assign shortcut ctrl+alt+j
(global-set-key (kbd "C-M-j") 'jump-next-colon)

If this is not exactly what you are looking for you can write your own macro. See http://emacswiki.org/emacs/KeyboardMacros

like image 1
ayckoster Avatar answered Nov 03 '22 01:11

ayckoster