r - How can I get Emacs ess to recognize a query string (within quotes) as code? -
background
i have function dbquery
simplifies process of querying mysql database within r.
dbquery <- function(querystring) { dvr <- dbdriver("mysql") con <- dbconnect(dvr, group = "databasename") q <- dbsendquery(con, querystring) data <- fetch(q, n = -1) return(data) }
thus can send:
dbquery(querystring = "select field_1, field_2, field_3 table_a join table_b on = join table_c on = field_4 in (1,2,3);"
however, variable querystring
must contained within quotes. makes emacs ess not nicely indent queries if in sql mode - or if there no quotes in ess-r mode.
question
is possible ess this? perhaps writing function accept query without quote (and add quotes within function), or perhaps adding .emacs or ess.el?
i think want in mmm mode. name suggests: multimajormode mode allows have multiple modes on different regions of same buffer.
i recommend checkout examples in http://www.emacswiki.org/emacs/htmlmodedeluxe give idea how in case (you might want add comment in code around sql mmm can find sql code).
you have guess (untested):
(require 'mmm-mode) (mmm-add-group 'sql-in-ess '( (sql-query :submode sql-mode :face whateveryouwant :front "#sql_query>" :back "#<sql_query")) (add-to-list 'mmm-mode-ext-classes-alist '(ess-mode nil sql-in-ess))
however, might overkill, unless happens lot have complex sql queries in r code.
Comments
Post a Comment