代码之家  ›  专栏  ›  技术社区  ›  PascalVKooten

哈希字符的Emacs函数

  •  1
  • PascalVKooten  · 技术社区  · 13 年前

    下面的函数应插入 # 如果在行的开头,如果不是,则应转到行的末尾并插入 # 。为什么这不起作用(它总是走到最后并插入 # ?

    (defun end-of-line-hash () 
      (interactive)
       (if (beginning-of-line)
           (insert "#")  
         (end-of-line)
         (insert "#"))
    )
    (global-set-key (kbd "#") 'end-of-line-hash)
    
    2 回复  |  直到 13 年前
        1
  •  3
  •   rwb    13 年前

    作用 beginning-of-line 将点移动到直线的起点。它可能会回来 nil 。试试这个。

    (defun end-of-line-hash () 
      (interactive)
       (if (= (point) (line-beginning-position))
           (insert "#")  
         (end-of-line)
         (insert "#"))
    )
    
        2
  •  0
  •   Community Mohan Dere    9 年前

    在的帮助下 rwb 的答案:

    (defun hash-character-ESS () 
      (interactive)
      (if (region-active-p) 
          (comment-region (region-beginning) (region-end))
        (if (= (point) (line-beginning-position))
            (insert "#")  
          (end-of-line)
          (insert "#")))
    )
    

    1) 如果选择了文本,请对区域进行注释。

    2) 若点(光标)在行的开头,则在其中插入#字符。

    3) 如果点不是前两个点中的任何一个,请将#放在线的末尾。

    推荐文章