Copyright | (c) Sergey Vinokurov 2018 |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | serg.foo@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- class MonadEmacs (m :: k -> Type -> Type) where
- type EmacsRef m :: k -> Type
- type EmacsReturn m :: k -> Type
- type EmacsFunction req opt rest (s :: k) (m :: k -> Type -> Type) = (Throws EmacsThrow, Throws EmacsError, Throws EmacsInternalError, Throws UserError) => EmacsArgs req opt rest (EmacsRef m s) -> m s (EmacsReturn m s)
- type EmacsFunctionExtra req opt rest extra (s :: k) (m :: k -> Type -> Type) = (Throws EmacsThrow, Throws EmacsError, Throws EmacsInternalError, Throws UserError) => EmacsArgs req opt rest (EmacsRef m s) -> Ptr extra -> m s (EmacsReturn m s)
- type UserPtrFinaliserType a = Ptr a -> IO ()
- type UserPtrFinaliser a = FunPtr (UserPtrFinaliserType a)
- data Nat
- data R a b = R !a !b
- data O a b = O !(Maybe a) !b
- newtype Rest a = Rest [a]
- data Stop a = Stop
- data EmacsError = EmacsError {}
- data EmacsInternalError = EmacsInternalError {}
- reportAllErrorsToEmacs :: Env -> IO a -> ((Throws EmacsInternalError, Throws EmacsError, Throws UserError, Throws EmacsThrow) => IO a) -> IO a
- data EmacsM s a
- runEmacsM :: Env -> (forall s. EmacsM s a) -> IO a
- module Emacs.Module.Functions
- module Data.Emacs.Module.Value
- data Env
- class Monad m => MonadThrow (m :: * -> *)
- class X e => Throws e
Generic interface
class MonadEmacs (m :: k -> Type -> Type) where Source #
produceRef, nonLocalExitCheck, nonLocalExitGet, nonLocalExitSignal, nonLocalExitThrow, nonLocalExitClear, freeValue, makeFunctionExtra, funcall, funcallPrimitive, funcallPrimitive_, intern, typeOf, isNotNil, eq, extractWideInteger, makeWideInteger, extractDouble, makeDouble, extractString, makeString, extractUserPtr, makeUserPtr, assignUserPtr, extractUserPtrFinaliser, assignUserPtrFinaliser, vecGet, vecSet, vecSize
type EmacsRef m :: k -> Type Source #
Emacs value that is managed by the m
monad. Will be cleaned up
after m
finishes its execution.
type EmacsReturn m :: k -> Type Source #
Type of values that Haskell functions may returns to Emacs.
produceRef :: EmacsRef m s -> m s (EmacsReturn m s) Source #
Return an EmacsRef
back to Emacs.
nonLocalExitCheck :: WithCallStack => m s (FuncallExit ()) Source #
Check whether a non-local exit is pending.
nonLocalExitGet :: WithCallStack => m s (FuncallExit (EmacsRef m s, EmacsRef m s)) Source #
Check whether a non-local exit is pending and get detailed data in case it is.
:: WithCallStack | |
=> EmacsRef m s | Error symbol |
-> [EmacsRef m s] | Error data, will be converted to a list as Emacs API expects. |
-> m s () |
Equivalent to Emacs's signal
function.
NB if a non-local exit is alredy pending, this function will not overwrite it. In order to do that, use nonLocalExitClear.
:: WithCallStack | |
=> EmacsRef m s | Tag |
-> EmacsRef m s | Data |
-> m s () |
Equivalent to Emacs's throw
function.
NB if a non-local exit is alredy pending, this function will not overwrite it. In order to do that, use nonLocalExitClear.
nonLocalExitClear :: WithCallStack => m s () Source #
Clean any pending local exits.
freeValue :: WithCallStack => EmacsRef m s -> m s () Source #
Make value eligible for collection during next GC within Emacs.
:: (WithCallStack, EmacsInvocation req opt rest, GetArities req opt rest) | |
=> (forall s'. EmacsFunctionExtra req opt rest extra s' m) | Haskell function to export |
-> ByteString | Documentation |
-> Ptr extra | Extra data to be passed to the Haskell function |
-> m s (EmacsRef m s) |
Make Haskell function available as an anonymoucs Emacs
function. In order to be able to use it later from Emacs it should
be fed into bindFunction
.
NB Each call to this function produces a small memory leak that will not be freed up. Hence, try not to create unbounded number of functions. This happens because GHC has to generate some wrapping code to convert between ccall and Haskell calling convention each time a function is exported. It is possible to free this code after function will not be used, but it's currently not supported.
:: WithCallStack | |
=> SymbolName | Function name |
-> [EmacsRef m s] | Arguments |
-> m s (EmacsRef m s) |
Invoke an Emacs function that may call back into Haskell.
:: WithCallStack | |
=> SymbolName | Function name |
-> [EmacsRef m s] | Arguments |
-> m s (EmacsRef m s) |
Invoke an Emacs function. The function should be simple and must not call back into Haskell.
:: WithCallStack | |
=> SymbolName | Function name |
-> [EmacsRef m s] | Arguments |
-> m s () |
Invoke an Emacs function and ignore its result. The function should be simple and must not call back into Haskell.
intern :: WithCallStack => SymbolName -> m s (EmacsRef m s) Source #
Convert a string to an Emacs symbol.
typeOf :: WithCallStack => EmacsRef m s -> m s (EmacsRef m s) Source #
Get type of an Emacs value as an Emacs symbol.
isNotNil :: WithCallStack => EmacsRef m s -> m s Bool Source #
Check whether Emacs value is not nil
.
eq :: WithCallStack => EmacsRef m s -> EmacsRef m s -> m s Bool Source #
Primitive equality. Tests whether two symbols, integers or characters are the equal, but not much more. For more complete equality comparison do
funcall [esym|equal|] [x, y]
extractWideInteger :: WithCallStack => EmacsRef m s -> m s Int64 Source #
Try to unpack a wide integer from a value.
makeWideInteger :: WithCallStack => Int64 -> m s (EmacsRef m s) Source #
Pack a wide integer for Emacs.
extractDouble :: WithCallStack => EmacsRef m s -> m s Double Source #
Try to unpack a floating-point number from a value.
makeDouble :: WithCallStack => Double -> m s (EmacsRef m s) Source #
Convert a floating-point number into Emacs value.
extractString :: WithCallStack => EmacsRef m s -> m s ByteString Source #
Extract string contents from an Emacs value.
makeString :: WithCallStack => ByteString -> m s (EmacsRef m s) Source #
Convert a utf8-encoded ByteString into an Emacs value.
extractUserPtr :: WithCallStack => EmacsRef m s -> m s (Ptr a) Source #
Extract a user pointer from an Emacs value.
:: WithCallStack | |
=> UserPtrFinaliser a | Finalisation action that will be executed when user pointer gets garbage-collected by Emacs. |
-> Ptr a | |
-> m s (EmacsRef m s) |
Pack a user pointer into an Emacs value.
assignUserPtr :: WithCallStack => EmacsRef m s -> Ptr a -> m s () Source #
Set user pointer to a new value
extractUserPtrFinaliser :: WithCallStack => EmacsRef m s -> m s (UserPtrFinaliser a) Source #
Extract a finaliser from an user_ptr.
assignUserPtrFinaliser :: WithCallStack => EmacsRef m s -> UserPtrFinaliser a -> m s () Source #
Assign new finaliser into an user_ptr.
vecGet :: WithCallStack => EmacsRef m s -> Int -> m s (EmacsRef m s) Source #
Extract an element from an Emacs vector.
:: WithCallStack | |
=> EmacsRef m s | Vector |
-> Int | Index |
-> EmacsRef m s | New value |
-> m s () |
Assign an element into an Emacs vector.
vecSize :: WithCallStack => EmacsRef m s -> m s Int Source #
Get size of an Emacs vector.
Instances
Type synonyms
type EmacsFunction req opt rest (s :: k) (m :: k -> Type -> Type) = (Throws EmacsThrow, Throws EmacsError, Throws EmacsInternalError, Throws UserError) => EmacsArgs req opt rest (EmacsRef m s) -> m s (EmacsReturn m s) Source #
type EmacsFunctionExtra req opt rest extra (s :: k) (m :: k -> Type -> Type) = (Throws EmacsThrow, Throws EmacsError, Throws EmacsInternalError, Throws UserError) => EmacsArgs req opt rest (EmacsRef m s) -> Ptr extra -> m s (EmacsReturn m s) Source #
type UserPtrFinaliserType a = Ptr a -> IO () Source #
type UserPtrFinaliser a = FunPtr (UserPtrFinaliserType a) Source #
Types for defining functions
Errors
data EmacsError Source #
A high-level error thrown when an Emacs function fails.
Instances
Show EmacsError Source # | |
Defined in Emacs.Module.Errors showsPrec :: Int -> EmacsError -> ShowS # show :: EmacsError -> String # showList :: [EmacsError] -> ShowS # | |
Exception EmacsError Source # | |
Defined in Emacs.Module.Errors toException :: EmacsError -> SomeException # fromException :: SomeException -> Maybe EmacsError # displayException :: EmacsError -> String # | |
Pretty EmacsError Source # | |
Defined in Emacs.Module.Errors pretty :: EmacsError -> Doc ann # prettyList :: [EmacsError] -> Doc ann # |
data EmacsInternalError Source #
A low-level error thrown when assumptions of this package are violated and it's not safe to proceed further.
Instances
Show EmacsInternalError Source # | |
Defined in Emacs.Module.Errors showsPrec :: Int -> EmacsInternalError -> ShowS # show :: EmacsInternalError -> String # showList :: [EmacsInternalError] -> ShowS # | |
Exception EmacsInternalError Source # | |
Defined in Emacs.Module.Errors | |
Pretty EmacsInternalError Source # | |
Defined in Emacs.Module.Errors pretty :: EmacsInternalError -> Doc ann # prettyList :: [EmacsInternalError] -> Doc ann # |
reportAllErrorsToEmacs Source #
:: Env | |
-> IO a | Result to return on error. |
-> ((Throws EmacsInternalError, Throws EmacsError, Throws UserError, Throws EmacsThrow) => IO a) | |
-> IO a |
Catch all errors this package might throw in an IO action and make Emacs aware of them.
This is a convenience function intended to be used around exported
initialise
entry point into an Emacs module.
EmacsM
Instances
Reexports
module Emacs.Module.Functions
module Data.Emacs.Module.Value
Third-party reexports
class Monad m => MonadThrow (m :: * -> *) #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Instances
A
constraint indicates a computation may throw synchronous
exception Throws
ee
. Introduce a constraint with throw
, and discharge it with
catch
.
You may ignore the X
superclass; it exists only to prevent additional
Throws
instances from being created.
Instances
Throws (Catch a) | |
Defined in Control.Exception.Safe.Checked |