helm-guideline.el

自分のコード綺麗って思ってんの? - ✘╹◡╹✘


普段 Rubyを書くことが皆無ですが、なんとなく helm interfaceを作ってみる。
現在編集中のファイルに guidelineを適用し、目的の場所にジャンプします。

コード

;;; helm-guideline.el --- guideline with helm interface

;; Copyright (C) 2012 by Syohei YOSHIDA

;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL:
;; Version: 0.01

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(eval-when-compile
  (require 'cl))

(require 'helm)

(defgroup helm-guideline nil
  "guideline with helm interface"
  :group 'helm)

(defun helm-c-guideline-init ()
  (let ((curfile (buffer-file-name)))
    (with-current-buffer (helm-candidate-buffer 'global)
      (let* ((cmd (format "guideline %s" curfile))
             (ret (call-process-shell-command cmd nil t nil)))
        (unless (= ret 0)
          (error "Failed helm-c-guideline-init"))
        (goto-char (point-min))
        (forward-line 1) ;; remove first line
        (delete-region (point-min) (point))))))

(defun helm-c-guideline-jump (message)
  (unless (string-match "^\\s-+\\([0-9]+\\)" message)
    (error "internal error"))
  (goto-line (string-to-int (match-string-no-properties 1 message))))

(defvar helm-c-guideline-source
  '((name . "helm guideline")
    (init . helm-c-guideline-init)
    (candidates-in-buffer)
    (action . helm-c-guideline-jump)
    (volatile)
    (candidate-number-limit . 9999)))

;;;###autoload
(defun helm-guideline ()
  (interactive)
  (let ((buf (get-buffer-create "*helm guideline*")))
    (helm :sources '(helm-c-guideline-source) :buffer buf)))

(provide 'helm-guideline)

;;; helm-guideline.el ends here

イメージ