Skip to content

Instantly share code, notes, and snippets.

@gifnksm
Created January 31, 2010 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gifnksm/291215 to your computer and use it in GitHub Desktop.
Save gifnksm/291215 to your computer and use it in GitHub Desktop.
(defun beginning-of-indented-line (current-point)
"インデント文字を飛ばした行頭に戻る。ただし、ポイントから行頭までの間にインデント文字しかない場合は、行頭に戻る。"
(interactive "d")
(if (minibuffer-window-active-p (get-buffer-window (current-buffer)))
(beginning-of-line)
(if (string-match
"^[ \t]+$"
(save-excursion
(buffer-substring-no-properties
(progn (beginning-of-line) (point))
current-point)))
(beginning-of-line)
(back-to-indentation))))
(defun beginning-of-visual-indented-line (current-point)
"インデント文字を飛ばした行頭に戻る。ただし、ポイントから行頭までの間にインデント文 字しかない場合は、行頭に戻る。"
(interactive "d")
(if (minibuffer-window-active-p (get-buffer-window (current-buffer)))
(beginning-of-line)
(let ((vhead-pos (save-excursion (progn (beginning-of-visual-line) (point))))
(head-pos (save-excursion (progn (beginning-of-line) (point)))))
(message (format "%d, %d" vhead-pos head-pos))
(cond
;; 物理行の1行目にいる場合
((eq vhead-pos head-pos)
(if (string-match
"^[ \t]+$"
(buffer-substring-no-properties vhead-pos current-point))
(beginning-of-visual-line)
(back-to-indentation)))
;; 物理行の2行目以降の先頭にいる場合
((eq vhead-pos current-point)
(backward-char)
(beginning-of-visual-indented-line (point)))
;; 物理行の2行目以降の途中にいる場合
(t (beginning-of-visual-line))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment