Function 哈希字符的Emacs函数

Function 哈希字符的Emacs函数,function,emacs,if-statement,line,Function,Emacs,If Statement,Line,下面的函数应该在行首插入一个,如果不是,则应该在行尾插入一个。为什么这不起作用(它总是在末尾插入一个# 函数行首将点移动到行首。它可能返回nil。请尝试此操作。 借助于的回答: (defun hash-character-ESS () (interactive) (if (region-active-p) (comment-region (region-beginning) (region-end)) (if (= (point) (line-beginning

下面的函数应该在行首插入一个
,如果不是,则应该在行尾插入一个
。为什么这不起作用(它总是在末尾插入一个
#


函数
行首
将点移动到行首。它可能返回
nil
。请尝试此操作。

借助于的回答:

(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) 如果点不是前两个点中的任何一个,请将#放在线的末尾。

您是否知道如何通过首先检查是否选择了区域来扩展此点?如果选择了区域,则应改为运行“注释区域”。这将使散列字符万能:)我真的做到了!我会在答案中贴出来:)(这是我在Emacs中做过的最高级的东西)
(defun end-of-line-hash () 
  (interactive)
   (if (= (point) (line-beginning-position))
       (insert "#")  
     (end-of-line)
     (insert "#"))
)
(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 "#")))
)