行または列の指定された位置に移動するには?

行または列の指定された位置に移動するには?

ファイルを開くときに使用できます。

$ emacs +2:9 practice.b

これにより、「practice.b」ファイルの行2とその行の文字9が開きます。すでに実行しているEmacsでこれをジャンプするにはどうすればよいですか?わかりました。M-x goto-lineしかし、セミコロンを認識しません。

ベストアンサー1

M-x goto-lineM-g gまたはM-g M-g)を使用すると、ターゲット行の先頭に移動します。その後、M-g | 8 RETM-x move-to-column 8 RET)を使用してターゲット列に移動できます(C-u 8 rightワイド文字がない場合は機能します)。 Emacsは0から始まる列の番号を付けますが、コマンドラインオプションは+LINE:COLUMN1から始まる列の番号を付けるため、列8になります。

入力できるEmacsコマンドが必要な場合は、次の2:9コードのいくつかをファイルに貼り付けて引数.emacsとして書き込むことができますgoto-line。このコードはEmacs 23でのみ最小限にテストされています。

(defadvice goto-line (around goto-column activate)
  "Allow a specification of LINE:COLUMN instead of just COLUMN.
Just :COLUMN moves to the specified column on the current line.
Just LINE: moves to the current column on the specified line.
LINE alone still moves to the beginning of the specified line (like LINE:0)."
  (if (symbolp line) (setq line (symbol-name line)))
  (let ((column (save-match-data
                  (if (and (stringp line)
                           (string-match "\\`\\([0-9]*\\):\\([0-9]*\\)\\'" line))
                      (prog1
                        (match-string 2 line)
                        (setq line (match-string 1 line)))
                    nil))))
    (if (stringp column)
        (setq column (if (= (length column) 0)
                         (current-column)
                       (string-to-int column))))
    (if (stringp line)
        (setq line (if (= (length line) 0)
                       (if buffer
                         (save-excursion
                           (set-buffer buffer)
                           (line-number-at-pos))
                         nil)
                     (string-to-int line))))
    (if line
        ad-do-it)
    (if column
        (let ((limit (- (save-excursion (forward-line 1) (point))
                        (point))))
          (when (< column limit)
            (move-to-column column))))))

おすすめ記事