本帖最后由 作者 于 2010-11-10 20:12:30 编辑
最近亚运比较闲,做了个看小说的lsp,就是在命令行里阅读txt文档
欢迎大家下载使用
如果大家有意见可以提出,或自行修改
其实这个lisp是一个双击鼠标的反应器
加载后第一次双击会要求打开一txt文本
然后再双击则逐行在命令行显示文本内容
在c盘会有一个阅读记录,记录你当前阅读到第几行
方便下次接着看
中午上传得太仓促
(defun opentext() 写成了
(defun C:opentext()
我把阅读的时候设成了一次显示两行
如果想只显示一行,找到这句可以自行修改
(setq n 2);一次阅读的行数
;忙里偷闲看书器 (if vlr-mouse-reactor1 (vlr-remove vlr-mouse-reactor1)) (setq vlr-mouse-reactor1 (vlr-mouse-reactor "DATA" '((:vlr-beginDoubleClick . mouse))) )
(defun mouse (vlrobj Lst)
(IF txt_path (progn (princ "\n") (repeat n (SETQ PRINC_TEXT NIL)
(WHILE (= PRINC_TEXT NIL) (get_page) (SETQ txt_ID (OPEN txt_path "r")) (REPEAT page (SETQ WORD (read-line txt_ID)) ) (if WORD (if (/= word "") (progn (princ page) (princ word) (SETQ PRINC_TEXT "T") );end progn );end if (SETQ PRINC_TEXT "T") );end if (CLOSE txt_ID ) (princ "\n") (reading_record) );end while
);end repeat
(if (= word nil) (princ "\n你的文档已经阅读完毕!")) (princ "\n") );end progn
(opentext)
);end if (princ) );end defun
(defun opentext() (setq txt_path (getfiled "选择要阅读的小说" "C:/Temp/" "txt" 0)) (setq n 2);一次阅读的行数 (princ) )
(defun reading_record()
(SETQ temp1_ID (OPEN "C://阅读记录.txt" "r")) (SETQ temp2_ID (OPEN "C://temp.txt" "w"))
(if temp1_ID (while (/= (SETQ TXT (read-line temp1_ID)) NIL) (IF (/= TXT "") (WRITE-LINE TXT temp2_ID) ) );end while );end if
(if temp1_ID (CLOSE temp1_ID ) ) (if temp2_ID (CLOSE temp2_ID ) )
(SETQ temp1_ID (OPEN "C://阅读记录.txt" "w")) (SETQ temp2_ID (OPEN "C://temp.txt" "r"))
(setq txt_name (car (cdr (fnsplitl txt_path)))) (setq txt_record nil)
(if temp2_ID (while (/= (SETQ TXT (read-line temp2_ID)) NIL) (IF (/= TXT "") (PROGN (if (AND (vl-string-search txt_name TXT) (= txt_record nil) ) (progn (WRITE-LINE (STRCAT txt_name (ITOA page) ) temp1_ID) (setq txt_record "t") );end progn (WRITE-LINE TXT temp1_ID) );end if );END PROGN );END IF );end while );end if
(if (= txt_record nil) (WRITE-LINE (STRCAT txt_name (ITOA page) ) temp1_ID) )
(if temp1_ID (CLOSE temp1_ID ) ) (if temp2_ID (CLOSE temp2_ID ) )
(vl-file-delete "C://temp.txt")
);end defun
(defun get_page()
(setq txt_name (car (cdr (fnsplitl txt_path)))) (SETQ temp1_ID (OPEN "C://阅读记录.txt" "r")) (setq page nil)
(if temp1_ID (while (/= (SETQ TXT (read-line temp1_ID)) NIL) (IF (vl-string-search txt_name TXT) (setq page (ATOI (SUBSTR TXT (1+ (STRLEN txt_name)))) ) ) );end while );end if
(IF (= page NIL) (SETQ page 0) (SETQ page (1+ page)) );end if
(if temp1_ID (CLOSE temp1_ID ) )
);end defun
|