2014-07-26 88 views
1

例如,我试图返回位于当前(point)以上一行的位置的缓冲区char位置。我的全部功能如下。elisp:如何在当前点之上获得点一条线?

我认为(point)是字符位置,所以我想减去当前点和当前点之上的位置之间的字符数。但是,这取决于当前点上方的线的长度(它并不总是等于frame-char-height)。

我试图模仿Eclipse的评论功能,其中当选择一个区域,最底层的线(与指针线)不包括在评论区:

(defun comment-eclipse (&optional arg) 
    (interactive) 
    (let ((start (line-beginning-position)) 
     (end (line-end-position))) 
    (when (or (not transient-mark-mode) (region-active-p)) 
     (setq start (save-excursion 
        (goto-char (region-beginning)) 
        (beginning-of-line) 
        (point)) 
      end (save-excursion 
        (goto-char (region-end)) 
        (end-of-line) 
        (point)))) ;; HERE: I want to return something like (- (point) (line-length)) 
    (comment-or-uncomment-region start end))) 

任何建议如何实现这个目标将不胜感激。

UPDATE

由于lunaryorn下面的回答,我已经提高了我的功能如下:

(defun comment-eclipse (&optional arg) 
    (interactive) 
    (let ((start (line-beginning-position)) 
     (end (line-end-position))) 
    (when (or (not transient-mark-mode) (region-active-p)) 
     (setq start (save-excursion 
        (goto-char (region-beginning)) 
        (beginning-of-line) 
        (point)) 
      end (save-excursion 
        (goto-char (region-end));;move point to region end 
        (end-of-line);;move point to end of line 
        (forward-line -1) 
        (end-of-line) 
        (point)))) 
    (comment-or-uncomment-region start end))) 

回答

7

使用的current-column组合来得到一个线上的电流列,forward-line导航到另一行,并且move-to-column还原新行上的列:

(let ((column (current-column))) 
    (forward-line -1) 
    (move-to-column column)) 
相关问题