Coder Social home page Coder Social logo

Comments (3)

vspinu avatar vspinu commented on July 19, 2024

I will solve this some day in a general, non ESS specific, way. For time
being, please add empty lines before and after the code.

On 29 July 2013 06:29, Peter Meilstrup [email protected] wrote:

Open an .Rmd file and type in

testing...

x <- function() {
  1
}

Position cursor in the function and type C-c C-c, C-c C-p, or such. It
tries to evaluate the lines with the backticks along with the lines
belonging to the function.


Reply to this email directly or view it on GitHubhttps://github.com//issues/6
.

from polymode.

troyac avatar troyac commented on July 19, 2024

This works for me:

(defun Rmd-setup ()
  (setq paragraph-start "```\\|\\s-*$")
  (setq paragraph-separate "```\\|\\s-*$"))

(add-hook 'poly-markdown+r-mode-hook 'Rmd-setup)

from polymode.

plantarum avatar plantarum commented on July 19, 2024

I encountered a related issue trying to evaluate functions from within fenced code blocks. The backticks in the fences, or apostrophes in the preceding markdown chunk, will make ESS think it is inside a string, and so refuse to evaluate the code. A possible approach to fixing this issue, and the one that @crowding raised, is the following advice:

EDITED Jan 27 - forgot the else clause!

(defun pm-ess-limit-eval-to-chunk (orig-fun &rest args)
  "Wrapper for ess-eval-functions.
Without this, apostrophes in the preceding text chunk cause
ess-mark-function, ess-send-function to fail, thinking they are inside a
string. Similarly, ess-eval-paragraph gets confused by the fence rows."
  (interactive)
  (let (res)
    (if poly-markdown+r-mode
        (save-restriction
          (pm/narrow-to-span)
          (setq res (apply orig-fun args)))
      (setq res (apply orig-fun args)))
    res))

(advice-add 'ess-beginning-of-function :around #'pm-ess-limit-eval-to-chunk)
(advice-add 'ess-eval-paragraph :around #'pm-ess-limit-eval-to-chunk)

Since this code will only modify the behaviour of the functions in question from within polymode, it should be safe to apply generally. However, there may be better solutions than global advice? If not, I can wrap this up in a pull request.

from polymode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.