Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better handling of noweb. I think it Came from Denis Haine and

Martin Maechler.
  • Loading branch information...
commit 9fe8269d3e14bd083d8c0f00fb40dc33881192a8 1 parent 1bb2a84
@mlf176f2 authored
View
74 Readme.org
@@ -1,18 +1,17 @@
#+TITLE: ESS Smart Underscore
#+AUTHOR: Matthew L. Fidler
-
* Library Information
- *ess-smart-underscore.el* --- Ess Smart Underscore
+ /ess-smart-underscore.el/ --- Ess Smart Underscore
- Filename :: [[file:ess-smart-underscore.el][ess-smart-underscore.el]]
- Description :: ess-smart-underscore
- Author :: Matthew L. Fidler
- Maintainer :: Matthew Fidler
- Created :: Thu Jul 14 11:04:42 2011 (-0500)
- - Version :: 0.73
- - Last-Updated :: Wed Aug 8 18:42:23 2012 (-0500)
+ - Version :: 0.74
+ - Last-Updated :: Mon Apr 9 15:27:09 2012 (-0500)
- By :: Matthew L. Fidler
- - Update # :: 151
+ - Update # :: 137
- URL :: http://github.com/mlf176f2/ess-smart-underscore.el
- Keywords :: ESS, underscore
Compatibility:
@@ -81,18 +80,65 @@ operator is removed and replaced by the underscore. =ess-S-assign=,
typically " <- ", can be customized. In ESS modes other than R/S,
an underscore is always inserted.
+In addition the ess-smart-underscore attempts to work with noweb-mode
+
* History
- - 08-Aug-2012 :: Updated the documentation to have the R code preformatted. (Matthew L. Fidler)
- - 07-Aug-2012 :: Attempt to upload and convert again. (Matthew L. Fidler)
- - 07-Aug-2012 :: Added more information to Readme.org (Matthew L. Fidler)
- - 07-Aug-2012 :: Added Readme.org (Matthew L. Fidler)
- - 07-Aug-2012 :: Added readme.org (Matthew L. Fidler)
- - 07-Aug-2012 :: Added readme.org (Matthew L. Fidler)
- - 07-Aug-2012 :: To use, put (require 'ess-smart-underscore) in your ~/.emacs file (Matthew L. Fidler)
- - 07-Aug-2012 :: Added a Readme.org (Matthew L. Fidler)
+ - 05-Nov-2012 :: Better handling of noweb. I think it Came from Denis Haine and Martin Maechler. (Matthew L. Fidler)
- 22-Feb-2012 :: Support unbalanced sexps. (Matthew L. Fidler)
- 02-Feb-2012 :: Took out auto-installing. Most package managers don't want you to do this. (Matthew L. Fidler)
- 03-Aug-2011 :: Bug fix for parenthetical statement (Matthew L. Fidler)
- 20-Jul-2011 :: Changed to allow underscore instead of assign when inside a parenthetical statement. (Matthew L. Fidler)
- - 15-Jul-2011 :: Bug fix for d[d$CMT == 2,"DV"] _ to produce d[d$CMT == 2,"DV"] <- (Matthew L. Fidler)
+ - 15-Jul-2011 :: Bug fix for d[d$CMT == 2,"DV"] _ to produce d[d$CMT == 2,"DV"] <- (Matthew L. Fidler)* Functions
+** Interactive Functions
+
+*** ess-smart-underscore
+=(ess-smart-underscore)=
+
+Smart "_" key: insert =ess-S-assign=, unless in string/comment.
+If the underscore key is pressed a second time, the assignment
+operator is removed and replaced by the underscore. =ess-S-assign=,
+typically " <- ", can be customized. In ESS modes other than R/S,
+an underscore is always inserted.
+
+** Internal Functions
+* Variables
+** Customizable Variables
+
+*** ess-S-space-underscore-is-assignment
+Should underscore produce =ess-S-assign= when a space is right before the cursor.
+
+Used by M-x ess-smart-underscore.
+
+*** ess-S-underscore-after-$
+Should underscore produce an underscore if it is an element of a list/data structure?
+
+ Used by M-x ess-smart-underscore.
+
+*** ess-S-underscore-after-<-or-=
+Should underscore produce an underscore if it is after a "<-" or "="?
+
+ Used by M-x ess-smart-underscore.
+
+*** ess-S-underscore-after-defined
+Should underscore produce an underscore if it is after a variable has been defined?
+
+ Used by M-x ess-smart-underscore.
+
+*** ess-S-underscore-when-inside-paren
+Should an underscore be produced instead of =ess-S-assign= when inside a parenthetical expression?
+
+*** ess-S-underscore-when-inside-unbalanced-parenthesis
+Should an underscore be produced instead of =ess-S-assign= when inside an unbalanced parenthetical expression such as:
+
+ foo(bar_
+
+This requires =ess-S-underscore-when-inside-paren= to be true.
+
+*** ess-S-underscore-when-last-character-is-a-space
+ESS produces an underscore only when the last character is not a space or a tab.
+
+*** ess-S-underscore-when-variable-contains-underscores
+Should an underscore be produced instead of =ess-S-assign= when variable already contains an underscore?
+
+** Internal Variables
View
5 el-get/ess-smart-underscore
@@ -0,0 +1,5 @@
+(:name ess-smart-underscore
+ :description "ess-smart-underscore"
+ :website "https://github.com/mlf176f2/ess-smart-underscore.el"
+ :type git
+ :url "https://github.com/mlf176f2/ess-smart-underscore.el.git")
View
194 ess-smart-underscore.el
@@ -5,7 +5,7 @@
;; Author: Matthew L. Fidler
;; Maintainer: Matthew Fidler
;; Created: Thu Jul 14 11:04:42 2011 (-0500)
-;; Version: 0.73
+;; Version: 0.74
;; Last-Updated: Mon Apr 9 15:27:09 2012 (-0500)
;; By: Matthew L. Fidler
;; Update #: 137
@@ -22,11 +22,74 @@
;;
;;; Commentary:
;;
-;; To use, put (require 'ess-smart-underscore) in your ~/.emacs file
+;; * Installation
+;;
+;; To use without using a package manager:
+;;
+;; - Put the library in a directory in the emacs load path, like ~/.emacs.d
+;; - Add (require 'ess-smart-underscore) in your ~/.emacs file
+;;
+;; This is in emacswiki, so this package can also be installed using el-get.
+;;
+;; After installing el-get, Type M-x el-get-install ess-smart-underscore.
+;; * Ess-Smart Underscore Package Information
+;; Smart "_" key: insert `ess-S-assign', unless:
+;;
+;; 1. in string/comment
+;; 2. after a $ (like d$one_two) (toggle with `ess-S-underscore-after-$')
+;; 3. when the underscore is part of a variable definition previously defined.
+;; (toggle with `ess-S-underscore-after-defined')
+;; 4. when the underscore is after a "=" or "<-" on the same line.
+;; 5. inside a parenthetical statement () or [].
+;; (toggle with `ess-S-underscore-when-inside-paren')
+;; 6. At the beginning of a line.
+;; 7. In a variable that contains underscores already (for example foo_a)
+;; (toggle with `ess-S-underscore-when-variable-contains-underscores')
+;; 8. The preceding character is not a tab/space (toggle with
+;; `ess-S-underscore-when-last-character-is-a-space'. Not enabled
+;; by default.)
+;;
+;; An exception to
+;;
+;;
+;; a <- b |
+;;
+;;
+;; Pressing an underscore here would produce
+;;
+;;
+;;
+;; a <- b <-
+;;
+;;
+;; However when in the following situation
+;;
+;;
+;; a <- b|
+;;
+;;
+;; Pressing an underscore would produce
+;;
+;;
+;; a <- b_
+;;
+;;
+;; This behavior can be toggled by `ess-S-space-underscore-is-assignment'
+;;
+;; If the underscore key is pressed a second time, the assignment
+;; operator is removed and replaced by the underscore. `ess-S-assign',
+;; typically " <- ", can be customized. In ESS modes other than R/S,
+;; an underscore is always inserted.
+;;
+;; In addition the ess-smart-underscore attempts to work with noweb-mode
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
+;; 05-Nov-2012 Matthew L. Fidler
+;; Last-Updated: Mon Apr 9 15:27:09 2012 (-0500) #137 (Matthew L. Fidler)
+;; Better handling of noweb. I think it Came from Denis Haine and
+;; Martin Maechler.
;; 22-Feb-2012 Matthew L. Fidler
;; Last-Updated: Wed Feb 22 20:27:04 2012 (-0600) #120 (Matthew L. Fidler)
;; Support unbalanced sexps.
@@ -168,65 +231,74 @@ an underscore is always inserted. "
;;(insert (if (ess-inside-string-or-comment-p (point)) "_"
;;ess-S-assign))
(message "%s" (looking-back "_[^ \t\n]*?\\="))
- (if (or
- (not (equal ess-language "S"))
- (looking-back "^[ \t\n]*\\=")
- (and ess-S-underscore-when-variable-contains-underscores
- (looking-back "_[^ \t\n]*?\\="))
- (and ess-S-underscore-when-last-character-is-a-space
- (looking-back "[^ \t]\\="))
- (ess-inside-string-or-comment-p (point))
- ;; Data
- (and ess-S-underscore-after-$ (save-match-data (save-excursion (re-search-backward "\\([$]\\)[A-Za-z0-9.]+\\=" nil t))))
- (and ess-S-underscore-after-<-or-=
- (let ((ret (save-match-data (and (not (looking-back ess-S-assign))
- (looking-back "\\(<-\\|\\<=\\>\\).*")))))
- (if (and ret ess-S-space-underscore-is-assignment
- (looking-back "[ \t]"))
- (setq ret nil))
- (symbol-value 'ret)))
- ;; Look for variable
- (and ess-S-underscore-after-defined
- (not (looking-back ess-S-assign)) ; Hack to fix bug
- (save-match-data
- (save-excursion
- (let (word)
- (when (looking-back "\\<[A-Za-z0-9.]+[ \t]*")
- (setq word (match-string 0))
- (setq ret
- (or (re-search-backward (format "^[ \t]*%s_[A-Za-z0-9.]*[ \t]*\\(<-\\|=\\)" word) nil t)
- (re-search-backward (format "->[ \t]*%s_[A-Za-z0-9.]*[ \t]*$" word) nil t)))
- (symbol-value 'ret))))))
- (and ess-S-underscore-when-inside-paren
- (save-match-data
- (save-excursion
- (let ((pt (point))
- ret)
- (when (re-search-backward "\\((\\|\\[\\).*\\=" nil t)
- (condition-case err
- (progn
- (forward-sexp)
- (when (> (point) pt)
- (setq ret t)))
- (error
- (when ess-S-underscore-when-inside-unbalanced-parenthesis
- (setq ret 't)))))
- (symbol-value 'ret))))))
- (insert "_")
- ;; Else one keypress produces ess-S-assign; a second keypress will delete
- ;; ess-S-assign and instead insert _
- ;; Rather than trying to count a second _ keypress, just check whether
- ;; the current point is preceded by ess-S-assign.
- (let ((assign-len (length ess-S-assign)))
- (if (and
- (>= (point) (+ assign-len (point-min))) ;check that we can move back
- (looking-back ess-S-assign))
- ;; If we are currently looking at ess-S-assign, replace it with _
- (progn
- (replace-match "")
- (insert "_"))
- (delete-horizontal-space)
- (insert ess-S-assign)))))
+ (save-restriction
+ (ignore-errors
+ (when (and (eq major-mode 'inferior-ess-mode)
+ (> (point) (process-mark (get-buffer-process
+ (current-buffer)))))
+ (narrow-to-region (process-mark (get-ess-process)) (point-max)))
+ (and ess-noweb-mode
+ (noweb-in-code-chunk)
+ (noweb-narrow-to-chunk)))
+ (if (or
+ (not (equal ess-language "S"))
+ (looking-back "^[ \t\n]*\\=")
+ (and ess-S-underscore-when-variable-contains-underscores
+ (looking-back "_[^ \t\n]*?\\="))
+ (and ess-S-underscore-when-last-character-is-a-space
+ (looking-back "[^ \t]\\="))
+ (ess-inside-string-or-comment-p (point))
+ ;; Data
+ (and ess-S-underscore-after-$ (save-match-data (save-excursion (re-search-backward "\\([$]\\)[A-Za-z0-9.]+\\=" nil t))))
+ (and ess-S-underscore-after-<-or-=
+ (let ((ret (save-match-data (and (not (looking-back ess-S-assign))
+ (looking-back "\\(<-\\|\\<=\\>\\).*")))))
+ (if (and ret ess-S-space-underscore-is-assignment
+ (looking-back "[ \t]"))
+ (setq ret nil))
+ (symbol-value 'ret)))
+ ;; Look for variable
+ (and ess-S-underscore-after-defined
+ (not (looking-back ess-S-assign)) ; Hack to fix bug
+ (save-match-data
+ (save-excursion
+ (let (word)
+ (when (looking-back "\\<[A-Za-z0-9.]+[ \t]*")
+ (setq word (match-string 0))
+ (setq ret
+ (or (re-search-backward (format "^[ \t]*%s_[A-Za-z0-9.]*[ \t]*\\(<-\\|=\\)" word) nil t)
+ (re-search-backward (format "->[ \t]*%s_[A-Za-z0-9.]*[ \t]*$" word) nil t)))
+ (symbol-value 'ret))))))
+ (and ess-S-underscore-when-inside-paren
+ (save-match-data
+ (save-excursion
+ (let ((pt (point))
+ ret)
+ (when (re-search-backward "\\((\\|\\[\\).*\\=" nil t)
+ (condition-case err
+ (progn
+ (forward-sexp)
+ (when (> (point) pt)
+ (setq ret t)))
+ (error
+ (when ess-S-underscore-when-inside-unbalanced-parenthesis
+ (setq ret 't)))))
+ (symbol-value 'ret))))))
+ (insert "_")
+ ;; Else one keypress produces ess-S-assign; a second keypress will delete
+ ;; ess-S-assign and instead insert _
+ ;; Rather than trying to count a second _ keypress, just check whether
+ ;; the current point is preceded by ess-S-assign.
+ (let ((assign-len (length ess-S-assign)))
+ (if (and
+ (>= (point) (+ assign-len (point-min))) ;check that we can move back
+ (looking-back ess-S-assign))
+ ;; If we are currently looking at ess-S-assign, replace it with _
+ (progn
+ (replace-match "")
+ (insert "_"))
+ (delete-horizontal-space)
+ (insert ess-S-assign))))))
(provide 'ess-smart-underscore)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
View
139 ess-smart-underscore.texi
@@ -0,0 +1,139 @@
+\input texinfo
+@documentencoding UTF-8
+
+@ifnottex
+@paragraphindent 0
+@end ifnottex
+@node Top
+@top Top
+
+@menu
+* ESS Smart Underscore::
+@end menu
+
+@node ESS Smart Underscore
+@chapter ESS Smart Underscore
+Matthew L. Fidler ## Library Information @emph{ess-smart-underscore.el} --- Ess Smart Underscore
+
+@itemize
+@item
+@strong{Filename} -- ess-smart-underscore.el
+@item
+@strong{Description} -- ess-smart-underscore
+@item
+@strong{Author} -- Matthew L. Fidler
+@item
+@strong{Maintainer} -- Matthew Fidler
+@item
+@strong{Created} -- Thu Jul 14 11:04:42 2011 (-0500)
+@item
+@strong{Version} -- 0.74
+@item
+@strong{Last-Updated} -- Mon Apr 9 15:27:09 2012 (-0500)
+@item
+@strong{By} -- Matthew L. Fidler
+@item
+@strong{Update #} -- 137
+@item
+@strong{URL} -- http:__github.com_mlf176f2_ess-smart-underscore.el
+@item
+@strong{Keywords} -- ESS@comma{} underscore Compatibility:
+@end itemize
+
+@menu
+* Possible Dependencies::
+* Installation::
+* History::
+@end menu
+
+@node Possible Dependencies
+@section Possible Dependencies
+@code{custom'@comma{}}easymenu'@comma{} @code{ess'@comma{}}ess-compat'@comma{} @code{ess-custom'@comma{}}font-lock'@comma{} @code{syntax'@comma{}}widget'.
+
+@node Installation
+@section Installation
+To use without using a package manager:
+
+@itemize
+@item
+Put the library in a directory in the emacs load path@comma{} like ~/.emacs.d
+@item
+Add (require 'ess-smart-underscore) in your ~/.emacs file
+@end itemize
+
+This is in emacswiki@comma{} so this package can also be installed using el-get.
+
+After installing el-get@comma{} Type M-x el-get-install ess-smart-underscore. ## Ess-Smart Underscore Package Information Smart "_" key: insert @code{ess-S-assign}@comma{} unless:
+
+@enumerate
+@item
+in string/comment
+@item
+after a $ (like d@math{one_two) (toggle with `ess-S-underscore-after-}`)
+@item
+when the underscore is part of a variable definition previously defined. (toggle with `ess-S-underscore-after-defined')
+@item
+when the underscore is after a "=" or "<-" on the same line.
+@item
+inside a parenthetical statement () or []. (toggle with @code{ess-S-underscore-when-inside-paren})
+@item
+At the beginning of a line.
+@item
+In a variable that contains underscores already (for example foo_a) (toggle with @code{ess-S-underscore-when-variable-contains-underscores})
+@item
+The preceding character is not a tab/space (toggle with @code{ess-S-underscore-when-last-character-is-a-space}. Not enabled by default.)
+@end enumerate
+
+An exception to #4 is in the following situation:
+
+a <- b |
+
+Pressing an underscore here would produce
+
+a <- b <-
+
+However when in the following situation
+
+a <- b|
+
+Pressing an underscore would produce
+
+a <- b_
+
+This behavior can be toggled by @code{ess-S-space-underscore-is-assignment}
+
+If the underscore key is pressed a second time@comma{} the assignment operator is removed and replaced by the underscore. @code{ess-S-assign}@comma{} typically " <- "@comma{} can be customized. In ESS modes other than R/S@comma{} an underscore is always inserted.
+
+In addition the ess-smart-underscore attempts to work with noweb-mode
+
+@node History
+@section History
+@itemize
+@item
+@strong{05-Nov-2012} -- Better handling of noweb. I think it Came from Denis Haine and Martin Maechler. (Matthew L. Fidler)
+@item
+@strong{22-Feb-2012} -- Support unbalanced sexps. (Matthew L. Fidler)
+@item
+@strong{02-Feb-2012} -- Took out auto-installing. Most package managers don't want you to do this. (Matthew L. Fidler)
+@item
+@strong{03-Aug-2011} -- Bug fix for parenthetical statement (Matthew L. Fidler)
+@item
+@strong{20-Jul-2011} -- Changed to allow underscore instead of assign when inside a parenthetical statement. (Matthew L. Fidler)
+@item
+@strong{15-Jul-2011} -- Bug fix for d[d@math{CMT `` 2,"DV"] _ to produce d[d}CMT `` 2@comma{}"DV"] <- (Matthew L. Fidler)* Functions ### Interactive Functions
+@end itemize
+
+@menu
+* Internal Functions::
+@end menu
+
+@node ess-smart-underscore
+@subsubsection ess-smart-underscore
+@code{(ess-smart-underscore)}
+
+Smart "_" key: insert @code{ess-S-assign}@comma{} unless in string/comment. If the underscore key is pressed a second time@comma{} the assignment operator is removed and replaced by the underscore. @code{ess-S-assign}@comma{} typically " <- "@comma{} can be customized. In ESS modes other than R/S@comma{} an underscore is always inserted.
+
+@node Internal Functions
+@subsection Internal Functions
+
+@bye
View
4 melpa/ess-smart-underscore
@@ -0,0 +1,4 @@
+(ess-smart-underscore
+ :repo "mlf176f2/ess-smart-underscore.el"
+ :fetcher github
+ :files ("ess-smart-underscore.el"))
Please sign in to comment.
Something went wrong with that request. Please try again.