emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel][bug] \ in detangling
@ 2011-01-13 16:27 Seth Burleigh
  2011-01-13 17:01 ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Seth Burleigh @ 2011-01-13 16:27 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 507 bytes --]

(defun org-babel-update-block-body (new-body)
  "Update the body of the current code block to NEW-BODY."
  (if (not (org-babel-where-is-src-block-head))
      (error "not in source block")
    (save-match-data
      (replace-match (concat (org-babel-trim new-body) "\n") nil t nil 5))
    (indent-rigidly (match-beginning 5) (match-end 5) 2)))

replace-match argument should be t instead of nil (as shown), otherwise \ is
treated as a special character and you cant detangle code with that
character in it.

[-- Attachment #1.2: Type: text/html, Size: 635 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babel][bug] \ in detangling
  2011-01-13 16:27 [babel][bug] \ in detangling Seth Burleigh
@ 2011-01-13 17:01 ` Eric Schulte
  2011-01-13 17:16   ` Seth Burleigh
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2011-01-13 17:01 UTC (permalink / raw)
  To: Seth Burleigh; +Cc: emacs-orgmode

Thanks for pointing this out, I've just pushed up your change.

Cheers -- Eric

Seth Burleigh <wburle@gmail.com> writes:

> (defun org-babel-update-block-body (new-body)
>   "Update the body of the current code block to NEW-BODY."
>   (if (not (org-babel-where-is-src-block-head))
>       (error "not in source block")
>     (save-match-data
>       (replace-match (concat (org-babel-trim new-body) "\n") nil t nil 5))
>     (indent-rigidly (match-beginning 5) (match-end 5) 2)))
>
> replace-match argument should be t instead of nil (as shown), otherwise \ is
> treated as a special character and you cant detangle code with that
> character in it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babel][bug] \ in detangling
  2011-01-13 17:01 ` Eric Schulte
@ 2011-01-13 17:16   ` Seth Burleigh
  2011-01-13 17:54     ` Seth Burleigh
  0 siblings, 1 reply; 5+ messages in thread
From: Seth Burleigh @ 2011-01-13 17:16 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 901 bytes --]

thanks. also, when trying to detangle my code, i found another bug.

In the functions org-babel-tangle-jump-to--org and org-babel-detangle, it
uses  org-bracket-link-analytic-regexp to search for the [[file:]] links.
However, it does not include the comment in the regex (";;" in clojure), so
somehow [[name val]] in my code is matched as a link, and then it fails to
detangle.
Also, related, it doesnt include the comment in the regex to find the end of
the block, it just does (concat " " (regexp-quote block-name) " ends here").

Since i only want to detangle clojure code, i simply put this in my .emacs
file to fix it
 (setq org-bracket-link-analytic-regexp
(concat ";;[ ]*"
 "\\[\\["
 "\\(\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):\\)?"
 "\\([^]]+\\)"
 "\\]"
 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
 "\\]"
 ))

I suppose one would have to customize the first two comments per language.

[-- Attachment #1.2: Type: text/html, Size: 1668 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babel][bug] \ in detangling
  2011-01-13 17:16   ` Seth Burleigh
@ 2011-01-13 17:54     ` Seth Burleigh
  2011-01-13 21:09       ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Seth Burleigh @ 2011-01-13 17:54 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 159 bytes --]

Ive attached the file it fails on. Notice that it fails below the constants
macro, but if you're above it, it will succeed since it wont find the [[name
val]]

[-- Attachment #1.2: Type: text/html, Size: 163 bytes --]

[-- Attachment #2: general.clj --]
[-- Type: application/octet-stream, Size: 4179 bytes --]


;; [[file:~/Dropbox/.rep/clj-forex/clj-forex.org::*General][forex-util-general]]

(ns forex.util.general
  (:use utils.general forex.util.spawn forex.util.log)
  (:import (org.joda.time DateTime DateTimeZone Instant)))


(deftype AtomHash [val]
  Object
  (toString [this] (str "<AtomHash " @val ">"))
  clojure.lang.IPersistentMap
  ;;ILookup
  (valAt [this key] (get @val key))
  (valAt [this key notfound] (get @val key notfound))
  ;;IPersistentCollection
  (count [this] (.count @val))
  (empty [this]  {})
  (cons [this e]  (.cons @val e))
  (equiv [this gs] (or (identical? this gs)
                       (when (identical? (class this) (class gs))
                         (.equiv @val) gs)))
  (containsKey [this k] (or (and (get @val k) true) false))
  (entryAt [this k] (get @val k))
  ;;Seqable
  (seq [this] (seq @val))
  ;;Associative
  (assoc [this k g] (assoc @val k g))
  (assocEx [this k g] (assoc this k g))
  (without [this k] (.without @val k))
  clojure.lang.IDeref
  (deref [this] @val))

(defmethod clojure.core/print-method AtomHash [o w]
  (.write w (.toString o)))

(defn atom-hash [val]
  (is (map? val))
  (AtomHash. (atom val)))


(defn symbolicate
  "symbolicate symbols together. ignores things like whitespaces, just drops them!"
  [& args]
  (symbol (apply str args)))


;;TODO: add support for waiting on multiple objects, including sockets!
(defprotocol PWait
  (wait-for [this timeout units] [this timeout]))
;;copied from clojure source, but adding timeout wait-for
(defn beg
  "Alpha - subject to change.
  Returns a promise object that can be read with deref/@, and set,
  once only, with deliver. Calls to deref/@ prior to delivery will
  block. All subsequent derefs will return the same delivered value
  without blocking."
  {:added "1.1"}
  []
  (let [d (java.util.concurrent.CountDownLatch. 1)
        v (atom nil)]
    (reify 
      clojure.lang.IDeref
      (deref [_] (.await d) @v)
      PWait
      (wait-for [this timeout]
                (wait-for this timeout
                          java.util.concurrent.TimeUnit/MILLISECONDS))
      (wait-for [this timeout units]
                (if timeout
                  (.await d timeout units)
                  (do (.await d) true)))
      clojure.lang.IFn
      (invoke [this x] 
              (locking d
                (if (pos? (.getCount d))
                  (do (reset! v x)
                      (.countDown d)
                      x)
                  (throw
                   (IllegalStateException.
                    "Multiple deliver calls to a promise"))))))))

(defn give
  "Alpha - subject to change.
  Delivers the supplied value to the promise, releasing any pending
  derefs. A subsequent call to deliver on a promise will throw an exception."
  {:added "1.1"}
  [promise val]
  (promise val))

(defmacro awhen [test & body]
  `(when-let [~'it ~test]
     ~@body))

(defmacro naive-var-local-cache-strategy [var] 
 `(let [cache# (atom {})]
    (reify PCachingStrategy
      (retrieve [_ item#] (get @cache# item#))
      (cached? [_ item#] (contains? @cache# item#))
      (hit [this# _] this#)
      (miss [this# item# result#]
            (reset! cache# (swap! ~var assoc item# result#))
            this#))))

(defmacro constants [& args]
  `(do ~@(map (fn [[name val]] `(def ~name ~val)) (group args 2))))

(defmacro spawn-log [func]
  `(spawn (fn [] (try (~func) (catch Exception e#
                                (.printStackTrace e#) (severe e#))))))

(defonce *env* (atom {:timeframe 1440 :symbol "EURUSD"})) ;default +D1+, EURUSD
(defn env [key] (key @*env*))
(defn env! [map]
  (swap! *env* #(merge % map))
  map)

;;todo: fix private!
;;todo: ignores all nils?
(defmacro wenv [[& args] & body]
  `(binding [forex.util.general/*env*
             (atom (merge @@~#'*env* (hash-map ~@args)))]
     ~@body))

(defmacro with-write-lock [l & body]
  `(let [obj# ~l]
     (try (do (.lock (.writeLock obj#)) ~@body)
          (finally (.unlock (.writeLock obj#))))))

(defmacro with-read-lock [l & body]
  `(let [obj# ~l]
     (try (do (.lock (.readLock obj#)) ~@body)
          (finally (.unlock (.readLock obj#))))))

;; forex-util-general ends here

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babel][bug] \ in detangling
  2011-01-13 17:54     ` Seth Burleigh
@ 2011-01-13 21:09       ` Eric Schulte
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2011-01-13 21:09 UTC (permalink / raw)
  To: Seth Burleigh; +Cc: emacs-orgmode

I've pushed up a fix for this issue,

Instead of using language-specific comment regexps ob-jump-to-org now
keep looking for a block-start comment until it find one which has a
matching block-end comment.

Thanks for pointing out this error case -- Eric

Seth Burleigh <wburle@gmail.com> writes:

> Ive attached the file it fails on. Notice that it fails below the constants
> macro, but if you're above it, it will succeed since it wont find the [[name
> val]]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-13 21:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-13 16:27 [babel][bug] \ in detangling Seth Burleigh
2011-01-13 17:01 ` Eric Schulte
2011-01-13 17:16   ` Seth Burleigh
2011-01-13 17:54     ` Seth Burleigh
2011-01-13 21:09       ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).