Created
March 10, 2017 17:04
-
-
Save 4d47/54c3956fec92ac244944bca66ed2d59f to your computer and use it in GitHub Desktop.
kak-expand-region-el
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; emacs -script a.elisp -- a.html 12.1,12.1 | |
;; | |
;;TODO: Kakoune counts columns from 1, emacs from 0 | |
;; | |
(require 'package) | |
(package-initialize) | |
(require 'use-package) | |
(require 'expand-region) | |
(require 'html-mode-expansions) | |
;; (use-package expand-region | |
;; :config | |
;; (use-package html-mode-expansions)) | |
;; kak_selection_desc: anchor,cursor .. anchor_line.anchor_column,cursor_line.cursor_column | |
;; | |
;; (save-excursion (goto-char pos) (current-column)) | |
;; (line-number-at-pos POS) | |
(transient-mark-mode) | |
(defun column-number-at-pos (pos) | |
"Return the horizontal position of POS." | |
(save-excursion (goto-char pos) (current-column))) | |
;; parse a kakoune selection and sets it | |
(let* ((ac (split-string (nth 2 argv) "\\,")) | |
(anchor (split-string (nth 0 ac) "\\.")) | |
(cursor (split-string (nth 1 ac) "\\.")) | |
(anchor-line (string-to-number (nth 0 anchor))) | |
(anchor-column (string-to-number (nth 1 anchor))) | |
(cursor-line (string-to-number (nth 0 cursor))) | |
(cursor-column (1- (string-to-number (nth 1 cursor))))) | |
;; Move to file and set selection | |
(find-file (nth 1 argv)) | |
(goto-char (point-min)) | |
(forward-line (1- anchor-line)) | |
(move-to-column anchor-column) | |
(set-mark (point)) | |
(forward-line (- cursor-line (line-number-at-pos))) | |
(move-to-column cursor-column) | |
;; Expand region | |
(er/expand-region 1) | |
;; Output new kakoune selection | |
(princ (format "%s.%s,%s.%s\n" | |
(line-number-at-pos (mark)) | |
(column-number-at-pos (mark)) | |
(line-number-at-pos (point)) | |
(1+ (column-number-at-pos (point)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def expand %{ | |
select %sh{ | |
emacs -script ~/a.elisp -- $kak_bufname $kak_selection_desc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment